0% found this document useful (2 votes)
1K views5 pages

Chapter 3 Problem

This document contains 7 problems related to synchronization and interprocess communication. Problem 1 and 2 ask to list real-world applications that use IPC and require synchronization. Problem 3 provides an example code snippet using a semaphore for synchronization. Problem 4-7 describe classical synchronization problems and ask the reader to provide pseudocode solutions using semaphores, including barriers, two goats crossing a bridge, and traffic at a four-way intersection.

Uploaded by

Hoàng Nguyễn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (2 votes)
1K views5 pages

Chapter 3 Problem

This document contains 7 problems related to synchronization and interprocess communication. Problem 1 and 2 ask to list real-world applications that use IPC and require synchronization. Problem 3 provides an example code snippet using a semaphore for synchronization. Problem 4-7 describe classical synchronization problems and ask the reader to provide pseudocode solutions using semaphores, including barriers, two goats crossing a bridge, and traffic at a four-way intersection.

Uploaded by

Hoàng Nguyễn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Chapter 3 Problems

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;

wait(S); // S->value = 0, S->L = empty

val = buf; // val = 5

val += count(); // val = 10

wait(S); // S->value = -1, S->L = {p2} , p2 is blocked

buf = val; // buf = 10

signal(S); // S->value = 0, S->L = empty, p2 is woken up

val = buf; // val = 10

val += count(); // val = 15

buf = val // buf = 15

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 a) 4 processes runining concurrently

+ 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()

PROBLEM 6: TWO GOATS GOING OVER THE BRIDGE


Use semaphore to solve the famous story:

+ A narrow bridge which can allow a SINGLE goat to go over

+ Two goats want to go over the bridge.

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.

Use semaphore to solve the problem

You might also like