pthreads mutex vs semaphore

2019-01-21 00:03发布

What is the difference between semaphores and mutex provided by pthread library ?

8条回答
狗以群分
2楼-- · 2019-01-21 00:28

mutex is used to avoid race condition between multiple threads.

whereas semaphore is used as synchronizing element used across multiple process.

mutex can't be replaced with binary semaphore since, one process waits for semaphore while other process releases semaphore. In case mutex both acquisition and release is handled by same.

查看更多
Juvenile、少年°
3楼-- · 2019-01-21 00:29

This two articles explain great details about mutex vs semaphores Also this stack overflow answer tells the similar answer.

查看更多
登录 后发表回答