Ben Bacarisse wrote:
> naobi writes:
>
>> what is the difference between semaphores and mutex
>
> There's a C answer: (modern) C has mutexes but it does not have general
> semaphores.
>
> The more helpful answer is that a mutex is a binary semaphore.
>
> There's a group specifically for this kind of topic,
> comp.programming.threads, but it was rather something of a wasteland the
> last time dropped in. Maybe a topical question will revive it!
>
There seems to be a kind of terminology drift over the years. AFAIU a
semaphore was originally defined as the primitive mechanism, and a mutex was
a special case. Now the two have switched, probably because people confuse
theory with practice.
I've also noticed conflation of "condition variable" and "monitor". Today
they effectively mean the same thing. Both POSIX and C11 use the condition
variable API as a monitor, even though conditional variables can be used
without mutexes, particularly in concurrent environments without hardware
parallelism (i.e. cooperative threading).
naobi writes:
> what is the difference between semaphores and mutex
There's a C answer: (modern) C has mutexes but it does not have general
semaphores.
The more helpful answer is that a mutex is a binary semaphore.
There's a group specifically for this kind of topic,
comp.programming.threads, but it was rather something of a wasteland the
last time dropped in. Maybe a topical question will revive it!
--
Ben.
On 08/28/2014 07:27 AM, naobi wrote:
> what is the difference between semaphores and mutex
Not directly related to clc, but a mutex is sometimes seen as a
semaphore with one resource (some people would argue that a mutex is
more a locking primitive, and semaphore a signaling one).
They both protect/restrict a common resource in a multi-threaded
environment. Semaphores can have a given amount of resources to protect.
Both primitives have additional guarantees, such as memory barriers,
that ensure you do not have caching issues between multiple processors:
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_11
"naobi" wrote in message
news:51d1641f-7268-45c0-9d48-bfcc2c5b986b@googlegroups.com...
> what is the difference between semaphores and mutex
comp.programming.threads
Bill