I\'m trying to implement a binary tree supporting concurrent insertions (which could occur even between nodes), but without having to allocate a global lock or a separate mu
You could do something like this:
define a "queued lock" that consists of a free/busy flag plus a linked-list of pthread condition variables. access to the queued_lock is protected by a mutex
to lock the queued_lock:
to unlock:
when waiting thread unblocked by pthread_cond_signal:
Note that the mutex is locked only while the state of the queued_lock is being altered, not for the whole duration that the queued_lock is held.