Quote:
Originally Posted by Corona688
Quote:
Originally Posted by Loic Domaigne
Well, it's a tradition in POSIX threads to avoid semaphores whenever possible
How come?
Well, this is a joke coming from the comp.programming.threads NG.
The reason behind this joke is: in most of the cases, POSIX threads offers synchronization mechanisms that surpass what semaphores can offer. For instance, a mutex could be seen as a binary semaphore. But mutex is more efficient in the uncontended case (indeed, there is no kernel involvement. This is not the case for semaphore). Beside that, mutex can offer priority inheritance, something impossible with semaphore.
From my own experience, most of the time where semaphores are used in Pthreads program often results from a lack of Pthreads understanding. There are only very few specific cases where semaphores make more sense.
Cheers,
Loïc.