|
Boost : |
From: williamkempf_at_[hidden]
Date: 2001-08-12 08:17:55
--- In boost_at_y..., John Max Skaller <skaller_at_m...> wrote:
> So please comment. It is my understanding that
> events are
>
> a) more general
> b) harder to use
Condition variables *MUST* be used in conjunction with a mutex which
is locked before the wait, unlocked during the wait, and locked again
after the wait in a thread safe manner. Condition variables use an
interface that makes this hard to do wrong (with Boost.Threads it
becomes impossible). Events *MUST NOT* be used in conjunction with a
mutex, and if you attempt to you wind up with race conditions.
Nothing in their interface can prevent this misuse, and unfortunately
most programmers don't understand this danger. So events are
dangerous in comparison to condition variables. Further, there are
very few designs in which an event is the optimal synchronization
object to use, and even in those rare cases a condition variable can
easily be used instead, while the converse isn't true.
That said, those rare cases where an event is optimal are valid...
> than more specific synchronisation techniques. Would you agree?
> And, more for Bill: is there anything preventing an
> event synchronisation subsystem being added to the library?
No, event's can be trivially added to Boost.Threads, using the native
event objects in Win32 and condition variables in POSIX. However,
because of the reasons I gave above, this is not an extension that
I'll be making before submission. If people find a legitimate need
for them later we can discuss the pros and cons more carefully and
add events if we then deem them to be needed.
Bill Kempf
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk