Chapter 3 Problem
Chapter 3 Problem
PROBLEM 1
List 5 real applications (you haved used) that use IPC
1. Google Chrome
2. Messenger
3. Teamviewer
4. Skype
5. Google Driver
PROBLEM 2
List 5 applications / situations in real worlds that need synchornization
1. Google driver
2. dropbox
3. facebook
4. git
5. mail
PROBLEM 3
List 5 applications / situations in real worlds that need synchornization
1. Google driver
2. dropbox
3. facebook
4. git
5. mail
PROBLEM 4
For all the classical synchronization problems, run step by step a certain sequence of instructions among
the processes. Update the state of the used semaphores, and prove such sequence meets all the
requirements of the synchronization constraints.
S->value = 1;
S->L = empty;
buf = 5;
signal(S) // S->value = 1
PROBLEM 5: BARRIER
Barrier is a synchronization problem with the following constraints:
+ We have N processes
+ We need a point at which all the processes MUST reach in order to continue next instructions
2
An example in the above figure:
+ Figure b) 3 processes reach the barrier, they MUST wait for process C which hasn’t reached the barrier
+ Figure c) when all the processes reach the barrier, all of them can proceed with their next instructions
Use the semaphore to solve this synchronization problem. Write the program is pseudo-code like those
in the slides Hint: used counting semaphore.
(Ví dụ trong thực tế, chuyến xe bus chở khách du lịch đi về, cần phải đảm bảo mọi người lên xe thì xe
mới khởi hành đi về được)
n = 4
count = 0
mutex = Semaphore(1)
barrier = Semaphore(0)
mutex.wait()
count = count + 1
mutex.signal()
if count == n: barrier.signal()
barrier.wait()
//todo
barrier.signal()
3
+ Each goat is on one side of the bridge
Bridge = Semaphore(1)
Goat1 = Semaphore(1)
Goat2 = Semaphore(1)
Bridge.wait()
Goat.wait()
Goat.signal()
Bridge.signal()
PROBLEM 7: CROSSROAD
This is a real-word problem: crossroad is a place where two roads meet and cross each other
4
Suppose each road has two lanes.