none
difference between the mutex and semaphore

Answers

  • They have share common properties like they are both synchronization objects. Everything else is different, 

    Purpose: the comparison is right at the documentation of Synchronization Objects (Windows).

    The difference between the behavior of those two is a never-ending list. For example:

    Thread affinity:Mutex yes, semaphore no. As a result you would have safe-reentry: Mutex yes, semaphore no; as well as OS-cleanup-when-process-crash:Mutex yes (WAIT_ABANDONED), semaphore no (no change in count) etc. 



    Visual C++ MVP

    Monday, December 24, 2012 9:37 PM
  • Hi dpanchasara,

    Strictly speaking, a mutex is locking mechanism used to synchronize access to a resource. Only one task (can be a thread or process based on OS abstraction) can acquire the mutex. It means there will be ownership associated with mutex, and only the owner can release the lock (mutex).

    Semaphore is signaling mechanism (“I am done, you can carry on” kind of signal). For example, if you are listening songs (assume it as one task) on your mobile and at the same time your friend called you, an interrupt will be triggered upon which an interrupt service routine (ISR) will signal the call processing task to wakeup.


    Regards, http://www.shwetalodha.blogspot.in/

    Tuesday, December 25, 2012 4:42 AM

All replies

  • They have share common properties like they are both synchronization objects. Everything else is different, 

    Purpose: the comparison is right at the documentation of Synchronization Objects (Windows).

    The difference between the behavior of those two is a never-ending list. For example:

    Thread affinity:Mutex yes, semaphore no. As a result you would have safe-reentry: Mutex yes, semaphore no; as well as OS-cleanup-when-process-crash:Mutex yes (WAIT_ABANDONED), semaphore no (no change in count) etc. 



    Visual C++ MVP

    Monday, December 24, 2012 9:37 PM
  • Hi dpanchasara,

    Strictly speaking, a mutex is locking mechanism used to synchronize access to a resource. Only one task (can be a thread or process based on OS abstraction) can acquire the mutex. It means there will be ownership associated with mutex, and only the owner can release the lock (mutex).

    Semaphore is signaling mechanism (“I am done, you can carry on” kind of signal). For example, if you are listening songs (assume it as one task) on your mobile and at the same time your friend called you, an interrupt will be triggered upon which an interrupt service routine (ISR) will signal the call processing task to wakeup.


    Regards, http://www.shwetalodha.blogspot.in/

    Tuesday, December 25, 2012 4:42 AM
  • This is old question

    But you might like to refer Key points and Myths on mutex and semaphore


    Thanks Saurabh Sinha

    http://saurabhsinhainblogs.blogspot.in/


    Thursday, May 29, 2014 11:17 PM