Mega Search
23.2 Million


Sign Up

Make a donation  
Semaphores and mutex  
News Group: comp.lang.c

what is the difference between semaphores and mutex

Vote for best question.
Score: 0  # Vote:  0
Date Posted: 27-Aug-2014, at 10:27 PM EST
From: naobi
 
Re: Semaphores and mutex  
News Group: comp.lang.c
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).


Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 28-Aug-2014, at 11:58 AM EST
From:
 
Re: Semaphores and mutex  
News Group: comp.lang.c
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.

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 28-Aug-2014, at 10:52 AM EST
From: Ben Bacarisse
 
Re: Semaphores and mutex  
News Group: comp.lang.c
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


Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 28-Aug-2014, at 8:01 AM EST
From: Xavier Roche
 
Re: Semaphores and mutex  
News Group: comp.lang.c
"naobi"  wrote in message 
news:51d1641f-7268-45c0-9d48-bfcc2c5b986b@googlegroups.com...
> what is the difference between semaphores and mutex

comp.programming.threads

Bill



Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 28-Aug-2014, at 11:00 PM EST
From: Bill Cunningham