0

Is there any difference between the following two variables:

Mutex m;
Semaphore s = 1;

I think they are the same but in a video I am watching about a formula to the reader/writer problem, it says to use 5 semaphores, each of them starting at the value of 1. I find that interesting because I thought if you have a semaphore at the value of 1, then you would just use a mutex.

Hatefiend
  • 3,416
  • 6
  • 33
  • 74
  • @DougCurrie Thank you. I would have never known to search *Binary Semaphore*. This has all the information I needed. – Hatefiend Jun 16 '17 at 22:33

1 Answers1

0

Think of Mutex as being in a subset of the definition of a semaphore.

There is a good answer on Stack Overflow here: Difference between binary semaphore and mutex .

Mutex can be released only by thread that had acquired it, while you can signal semaphore from any other thread (or process), so semaphores are more suitable for some synchronization problems like producer-consumer.

Darrell Ulm
  • 132
  • 1
  • 2
  • 11