|
Threads-Devel : |
From: Anthony Williams (anthony_at_[hidden])
Date: 2007-04-11 03:36:23
Russell Kliese <russell_at_[hidden]> writes:
> I've been working on a project that used the boost timed read write
> mutex. I recently upgraded from Debian Sarge to Etch and discovered that
> these are no longer available (and found out that this was because of
> the dead-lock problems).
>
> I decided to come up with my own implementation of a timed read write
> mutex that makes use of the other boost mutex types. I have decided to
> share this implementation with the boost community in case it might
> provide inspiration. I'm not an expert on the subject of mutexes, so
> there may be flaws in my implementation --- I'm happy for any feedback.
Thank you for sharing your implementation. Unfortunately, this also suffers
from the potential of deadlock. If two readers acquire the lock, and both try
to upgrade, then they will deadlock. Also, if there are multiple readers, it
is possible that a different thread will try and unlock the "two or more"
mutex than the one that locked it. This is not necessarily safe. In general,
mutexes must be unlocked by the same thread that locked them.
I posted a general implementation of a read/write mutex a while back and there
is a win32-specific implementation which includes upgradeable locks in boost
CVS on the thread_rewrite branch. I have attached both here for your
convenience.
It should be straightforward to extend my generic solution along the lines of
the win32-specific one to support upgradeable locks.
Anthony
-- Anthony Williams Just Software Solutions Ltd - http://www.justsoftwaresolutions.co.uk Registered in England, Company Number 5478976. Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL