Both are synchronization objects but they carry great difference in the way they are used and implemented. While semaphore do have counting and binary semaphore as it types, many call binary semphore is similar to mutex. It is in the sense of using set or clear of a bit mechanism but they are not really the same.
Main difference between mutex and semaphore is,
+ a mutex when acquired by a thread needs to released in the same thread.
+ a sempahore can be released from another thread which has not acquired the semaphore
+ then comes the counting semphore where you define count and the number of waiting threads
One more important fact is both semaphore and mutex are not to be used in the ISRs as they are not automic mostly which might result in deadlocks. In ISRs, spinlocks are used with automic flag enabled.
I would like to see few comments/inputs here adding or debating on the usage.
No comments:
Post a Comment