Boost logo

Boost :

From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2003-06-04 15:21:13


Nicolas Fleury wrote:
>
> Alexander Terekhov wrote:
> > Nicolas Fleury wrote:
> > [...]
> >
> >>
> >>Would it be possible to post some code that "experience has shown" to be
> >>error-prone using semaphores comparing with conditions/mutexes?
> >
> >
> > Sure... thanks to the Microsoft Corp.
> >
> > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndllpro/html/msdn_metrsect.asp
> >
> > Take a look at their brain-damaged "metered section" semaphore
> > implementation. Note that MS "auto-reset event" is nothing but
> > a binary sema (well, brain-dead "pulsing" aside for a moment).
>
> Thx for the link, but I don't get it. How is Microsoft implementation
> of semaphore is showing that all implementations of semaphore should be
> avoided?

It is showing that semas (e.g. bin-semas aka "auto-reset events")
are really error-prone. Their implementation of counting semaphore
using a mutex (well, they actually use a totally brain-damaged
"dying spinlock") plus a binary semaphore is buggy (it contains
erroneous synchronization). Now... you might to follow this link:

http://google.com/groups?selm=3CE0BCD3.EF695748%40web.de
(Subject: Re: The implementation of condition variables in pthreads-win32)

regards,
alexander.

--
"Pthreads win32 is just trying to be a general pupose condition 
 variable as defined by the pthreads standard, suitable for any 
 and all threads to go around calling pthread_cond_wait() and 
 pthread_cond_signal() on. As a consequence the implementation 
 contains several mutexes, semaphores etc, and a flow of control 
 that will make your brains dribble out of your ears if you stare 
 at the code too long (I have the stains on my collar to prove it
 ;-). Such are the joys of implementing condition variables using 
 the Win32 synchronization primitives!"  
                                    -- <http://tinyurl.com/b9vw>

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk