[Ecls-list] [PATCH] Fix locks and condition variables.
Juan Jose Garcia-Ripoll
juanjose.garciaripoll at googlemail.com
Tue Sep 22 20:37:39 UTC 2009
2009/9/21 Alexander Gavrilov <angavrilov at gmail.com>:
> 3) Waiting on a condition variable temporarily gives up the
> lock, and restores the ownership before returning. This
> should be reflected in the lock structure fields.
> Failure mode for 3:
> - Thread A waits on a condition (count left at 1)
> - Thread B acquires the lock (count = 2)
> - Thread B releases the lock (count = 1, holder not reset)
> - Thread B acquires the lock
> (doesn't actually, since get-lock thinks that it already has it)
I committed as is, but I am still worried that a race condition may
still happen between steps 1 and 2, if A marks the lock as released,
but pthread_cond_wait() has not yet released it.
> 4) The lock counter is meaningless if the lock is not held
> by the current thread, so it is necessary to check both
> lock-count and lock-holder inside with-lock.
> Failure mode for 4:
> - Thread A acquires the lock, count = 1
> - Thread B reads the count
> - Thread A releases the lock, count = 0
> - Thread B acquires the lock via with-lock, count = 1
> - with-lock does not release the lock
Ok, this sounds reasonable. Also committed.
Instituto de Física Fundamental, CSIC
c/ Serrano, 113b, Madrid 28006 (Spain)
More information about the ecl-devel