I have a tree T
, nodes of which can be addressed by their paths (payloads of nodes contain some name
s that can be glued together into a path). What I would like to have is some mechanism (algorithm, auxiliary data structure etc.) that will allow, given the path P0
, lock an entire sub-tree in such a fashion that:
- attempts to lock on any path
P1
(whereP1 starts with P0
, i.e.P1
belongs to the locked subtree) will result in lock forP1
being the one forP0
(well, it might be not the very same lock, but operations onP1
should wait untilP0
lock is free); - but when
P0
lock is released, any lock forP2
, whereP2 starts with P0
, but notP2 starts with P1
, i.e.P2
subtree andP1
subtree are different, different locks will be granted for those two paths, and so on.
I tackled this task for a couple of times, but I wound up with an over-complicated code that was messy and used some kind of tree for storing locks itself, which was even heavier that the tree I tried to lock.
In case my question is unclear, please let me know if you'd like to see some drawings/diagrams or anything that would help.