multithreading - What is the difference between semaphore and mutex in implementation? -
i read mutex , binary semaphore different in 1 aspect, in case of mutex locking thread has unlock, in semaphore locking , unlocking thread can different?
which 1 more efficient?
assuming know basic differences between sempahore , mutex :
for fast, simple synchronization, use crticial section.
to synchronize threads across process boundaries, use mutexes.
to synchronize access limited resources, use semaphore.
apart fact mutexes have owner, 2 objects may optimized different usage. mutexes designed held short time; violating can cause poor performance , unfair scheduling. example, running thread may permitted acquire mutex, though thread blocked on it. semaphores may provide more fairness, or fairness can forced using several condition variables.
Comments
Post a Comment