Boost logo

Boost :

From: kevin_vanhorn_at_[hidden]
Date: 2001-10-17 09:09:03


I just noticed, to my dismay, that the thread library only implements
weak semaphores. That is, if the semaphore's logical value is
currently 0, there are threads blocked on the semaphore, and
some thread does an up() operation on the semaphore, then there is
no guarantee that one of the waiting threads will be unblocked;
in fact, the thread that issued the up() may immediately thereafter
issue a down() and catch the transient positive value of the
semaphore.

Weak semaphores aren't very useful. They're subject to race
conditions like the one just mentioned. All of the standard
semaphore algorithms require strong semaphores (if there are threads
blocked on the semaphore, an up() op always unblocks one of them)
to prevent starvation. In fact, many of the standard semaphore
algorithms require not just strong semaphores, but fair semaphores --
that is, a guarantee that if a thread is blocked on the semaphore
and an unending stream of up() ops occurs, that particular thread will
eventually be unblocked (it can't always be passed over in favor of
another blocked thread).


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