CS 551: Distributed Operating Systems
Example of Semaphore Use in DS
Example of Semaphore Use in DS
- Now consider a distributed system
with three running processes
- Process 1
- Process 2
- Process 3
- Each of the processes has access
to a shared semaphore, S
- Each process has a critical section
controlled by S
- Assume the semaphore/lock is controlled
by a centralized lock manager
- Initially S = 1
with no processes are in their critical section
- Steps:
- Process 3 requests its critical section
Since S = 1, S !<= 0
So S is decremented by 1
making S = 0
and
- Process 3 is granted access to its critical section
- Process 1 requests its critical section
But S <= 0, as S = 0
so
- So Process 1 is is placed on a queue
until S > 0
- Process 2 requests its critical section
But S <= 0, as S = 0
so
- Process 2 is queued
until S > 0
- Process 3 finishes its critical section
So S is incremented by 1
making S = 1
releasing access to the critical section
- The central manager checks the
semaphore value S
Since S = 1, S !<= 0
So S is decremented by 1
making S = 0
and
Process 1 is granted access to its critical section
by the central manager
- Process 1 finishes its critical section
So S is incremented by 1
making S = 1
releasing access to the critical section
- The central manager checks the
semaphore value S
Since S = 1, S !<= 0
So S is decremented by 1
making S = 0
and
Process 2 is granted access to its critical section
by the central manager
- Process 2 finishes its critical section
So S is incremented by 1
making S = 1
releasing access to the critical section
Comments:
Copyright © 2001-2003:
Colorado State University for CS 551.
All rights reserved.