Presentation is loading. Please wait.

Presentation is loading. Please wait.

Semaphores, mutexes and condition variables. semaphores Two types – Binary – 0 or 1 – Counting 0 to n Wait – decrements > 0 forces a wait Post or signal.

Similar presentations


Presentation on theme: "Semaphores, mutexes and condition variables. semaphores Two types – Binary – 0 or 1 – Counting 0 to n Wait – decrements > 0 forces a wait Post or signal."— Presentation transcript:

1 Semaphores, mutexes and condition variables

2 semaphores Two types – Binary – 0 or 1 – Counting 0 to n Wait – decrements > 0 forces a wait Post or signal – increments Lock/unlock – no restrictions

3 mutexes Owned by a thread – Must be unlocked by the locker – May be locked/unlocked in separate functions Attempts to get a locked mutex force caller to sleep

4 Condition variables Creates a safe environment for testing Forces sleep when false Operation – Lock a mutex – Test condition (values in condition must be protected by the mutex) If true, proceed with execution If false, the mutex is released for you and you are put to sleep on the condition variable Any thread changing the conditions, signals the condition variable, wakes up ONE sleeper You must reevaluate the condition or your program may fail (could have changed before your tslice)


Download ppt "Semaphores, mutexes and condition variables. semaphores Two types – Binary – 0 or 1 – Counting 0 to n Wait – decrements > 0 forces a wait Post or signal."

Similar presentations


Ads by Google