1

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.

1
  • @DougCurrie Thank you. I would have never known to search Binary Semaphore. This has all the information I needed. Commented Jun 16, 2017 at 22:33

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.