Friday, March 21, 2014

Mutex Vs Binary Semaphore

Most of the time people get confused with these two. So here I will try to explain the difference using this answer at Stack Overflow.

So Mutex is a lock which have the owner association, So it means whoever holds the mutex lock will only be able to unlock this mutex. So Mutex is used when you want to lock the resources.

While Binary Semaphore is used for signalling mechanism, It doesn't lock the resource. So any other thread can also unlock the semaphore held by your thread. In other words it signals your thread to do something.

No comments: