Helpful Information
 
 
Category: Embedded Programming
Binary semaphore and mutex

What is the main difference between binary semaphore and mutex?

This comes from a link (which I can't post yet):

"
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
Pieter

both used for synchronization but
semaphore used in child process and mutex is used in thread.

* Binary semaphore if the lock is not available, respective process will be stored in its own wait queue but in case of mutex they don't have its own wait queue and it should give the thread to the scheduler and the scheduler will execute the program when the CPU is free or when its turn comes.

* Mutex have ownership (owners can only release the lock) but the semaphores don't have the ownership over the process (if the process is completed the lock will be automatically released).

Please correct me if i am wrong.

Regards,
Sathishkumar.










privacy (GDPR)