|
Boost : |
From: William E. Kempf (wekempf_at_[hidden])
Date: 2003-06-04 16:48:22
Stefan Seefeld said:
> Alexander Terekhov wrote:
>
>> It is showing that semas (e.g. bin-semas aka "auto-reset events") are
>> really error-prone.
>
> you seem to equate microsoft's implementation of semaphores with
> the concept of semaphores (which is what I'd like to get feedback on).
No, you miss Alexander's point (which is easy to do, with his
communication style... in this case he points you to a good example, but
fails to explain why it's a good example).
His point is that the MS concept of an "auto-reset event" is the same
thing as a binary semaphore. The MeteredSection concept in this article
was implemented using an auto-reset event (bin-semaphore), and on the
surface looks like a reasonable implementation. However, if you do a
thorough analysis of this implementation you'll find that it's prone to
race conditions.
Another great example is the attempts to implement a condition variable
concept using semaphores, as has been done sooo many times on Windows.
Nearly every attempt has been flawed, and the valid solutions are
extremely complex.
> If all that is wrong is that microsoft does a crappy job at implementing
> them, the response could be to provide a special implementation using
> mutexes and cv's *for the MS platforms*, and using native
> implementations when possible.
MS's actual semaphore is as valid an implementation as any other
(Alexander will claim them to be "brain damaged", but that's because of
the design, not the implementation).
> As boost doesn't, there must clearly be other reasons for them not to do
> that.
There is, but the explanations are long and quite complex. That's why the
FAQ points you at a seminal paper on the subject, rather than attempting
to explain it. Like I've said in numerous arguments about the Event
concept, the problem with the concept isn't that it's broken or unusable,
only that it's difficult to actually use correctly. Most users think
their code is correct, when in fact they have race conditions waiting to
bite them. When Mutexes and Condition variables provide everything that
Semaphores and Events do, but in a way that's easier to use correctly, the
choice to not include Event's or Semaphore's is reasonable.
-- William E. Kempf
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk