|
Boost : |
From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2003-06-04 17:02:49
Nicolas Fleury wrote:
[...]
> > It is showing that semas (e.g. bin-semas aka "auto-reset events")
> > are really error-prone. Their implementation of counting semaphore
>
> How?
Review the code. You'll see that it has many problems. One problem
is precisely the thing that POSIX rationale is talking about -- the
predicate checking -- "With stateful primitives, such as binary
semaphores, the wakeup in itself typically means that the wait is
satisfied. The burden of ensuring correctness for such waits is
thus placed on all signalers of the semaphore rather than on an
explicitly coded Boolean predicate located at the condition wait."
[...]
> But what's the relation between Microsoft implementation of semaphore,
Damn. I should have called it "metered section"... without any
mentioning that it's a counting semaphore. The point is that that
code does illustrate the error-proness that POSIX rationale is
talking about.
> pthread win32 implementation of condition
http://groups.google.com/groups?selm=3CEA2764.3957A2C8%40web.de
> and the error-proness of semaphores versus mutexes/conditions
> in general?
In general, you don't need semas for threading and you do need
mutexes and condvars. "Mutexes and condition variables together
constitute an appropriate, sufficient, and complete set of inter-
thread synchronization primitives."
> Is it simply a mather of preference and style, or is there a simple case
> to show why semaphores are error-prone instead of mutexes/conditions?
Again, MS-"metered section" example IS "a simple case to show why
semaphores are error-prone instead of mutexes/conditions".
regards,
alexander.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk