Boost logo

Threads-Devel :

From: Anthony Williams (anthony_at_[hidden])
Date: 2006-03-02 11:03:25

Roland Schwarz <roland.schwarz_at_[hidden]> writes:

> Anthony Williams wrote:
>>It is legal to destroy a locked mutex object. The assert does not check for
>>that case --- it checks whether CloseHandle failed. CloseHandle will fail if
>>the handle is invalid, which therefore indicates a corrupt system, so it is a
>>good idea to terminate the app.
> So I understand you right, you are suggesting to fix the bug by
> first first locking the mutex and then CloseHandle?
> But if so, what about the changed semantics?
> The pthreads implementation does not wait for the lock to get
> free, but simply aborts the program in this case.

I'm not proposing anything --- this needs more thought. I thought that was
your suggestion, anyway.

I'm just pointing out that on Windows, it is legal to destroy a locked
mutex. Whether or not doing so constitutes a bug in the application is another
matter --- I suspect that it is in most cases.

I would want it to be illegal to destroy a boost::mutex if a lock is held, and
for the implementation to detect this, if possible.


Anthony Williams
Software Developer
Just Software Solutions Ltd

Threads-Devel list run by bdawes at, david.abrahams at, gregod at, cpdaniel at, john at