Homework 3 Solution

advertisement
Name______________________
Grade____________
CS 5204: Operating Systems
HOMEWORK 3
Spring Semester 1998
Assigned: 19 February 1998
Due: 24 February 1998
Your answer to each problem should follow the page describing that problem and
be stapled to the problem page. The entire problem set should be clipped
together in the proper order for submission. Please submit your answers in typed form
with writing on one side of the page only.
(40) 1.
A time sketch of requests to enter a CS is shown below. The CS is defined on a shared
variable among the three processes P1, P2, and P3. Note that while the time values are
given with respect to a global clock, no such clock is actually shared by the three
processes.
At time
At time
At time
At time
= 1. P2 sends REQUESTs to enter CS to both P1 and P3.
= 2. P3 sends REQUESTs to enter CS to both P1 and P2.
= 8. P1 sends REQUESTs to enter CS to both P2 and P3.
= 10. P2 sends REQUESTs to enter CS to both P1 and P3.
The processes P1, P2, and P3 spend 2, 2, and 3 time units respectively in the CS once given access.
All REPLY and RELEASE messages (in separate or combined form) take one time unit
in transit. REQUEST messages incur the latency delay shown in the matrix below.
Destination
P1 P2 P3
P1
-
1
2
Origin P
2
1
-
3
P3
3
2
-
The following is to be done for both the Lamport Algorithm (Section 6.6) and the
Ricart-Agrawala Algorithm (Section 6.7).
(a) Draw the space time diagram for the processes, clearly identifying
REQUEST messages by
REPLY messages by
RELEASE messages by
1
3
4
5
6
7
10
11
12
13
14
15
[[
9
[[ (10,2)
8
[[(6,1)(10,2)
2
[[ (1,3)(6,1)(10,2)
1
[[ (1,3)(6,1)
0
[[(1,2)(1,3)(6,1)
[[(1,2)
[[(1,2)(1,3)
Lamport
16
17
18
19
[ (6,1)(10,2)
[[(1,2)
[
[[(1,2)(1,3)
[(1,3)(6,1)
[ (10,2)
Ricart-Agrawala
1
2
3
4
[[ (1,3)
6
7
8
9
10
11
12
[[ (9,2) 13
[[(1,2)
14
[[
[[(10,2)
[[(1,6)(10,2)
[[(1,6)
[[(1,2)
[[(1,2)
[[(1,3)(6,1)
[[(1,3)
5
15
16
17
18
19
[
[[
[[(10,2)
[[
[[(6,1)
[[(1,2)
0
[[(1,2)(1,3)
[[(1,3)
[[(1,2)
[[(1,2)
[[(1,2)
[(1,3)
[(1,3)(6,1)(10,2)
Use either of the choices for a combined message, but designate the message type, e.g.
represents a REPLY/RELEASE message.
Apply green shading to show the periods in which each process is in the CS. Show the
request-queue contents for each process at each event in which a change occurs.
2
(b) Compute the performance in terms of number of messages exchanged,
synchronization delay and response time.
Note that at least one time unit must separate the receipt of a REQUEST and any
response. Messages from different processes can arrive at the same instant (define a
single event) for a third process. At least one time unit must separate the sending of
different types of messages from the same process (e.g. while REQUEST and
RELEASE messages may be broadcast at the same event time, a REPLY and
RELEASE from the same process must be separated by at least one time unit). A
process having received the necessary messages to enter the CS may do so immediately
(as part of that event). Please note any additional assumptions that you believe are
necessary.
Lamport:
Messages: 24
Messages per CS: 6
Synchronization delay: 1
Response time: 7.75
Ricart-Agrawala:
Messages: 16
Messages per CS: 4
Synchronization delay: 1
Response time: 7.75
(20) 2. Work the above problem using the Suzumi-Kasami Broadcast
Algorithm. Compare the performance of this token-based algorithm
Ricart-Agrawala Algorithm.
LN
[0,0,0]
0
1
[0,1,0]
[(0,1,0)
2
3
4
[(3,1)
[(2,1)
[(0,1,1)
5
6
7
[0,1,1]
[(1,1,1)
8
9
10
[(1,1)
11
with the
[0,1,0]
[(1,2,1)
12
13
14
15
[0,1,0]
16
17
18
[(2,2)
[(1,2,1)
[(0,1,0)
[(2,1)
[(0,1,1)
[(0,1,1)
[(1,1,1)
[(2,2)
[(3,1)
[(0,1,1)
[(1,1,1)
[(1,2,1)
3
19
Suzuki-Kasami:
Messages: 12
Messages per CS: 3
Synchronization delay: 1.33
Response time: 6.5
(20) 3.
Suppose that Process 2 desires to enter the CS a second time immediately after exiting
in Problem 1. Would the Roucairol and Carvalho improvement (see p. 129) result in
any savings here?
This would have no effect because P2 already has a deferred
request from P3.
(20) 4. With Maekawa’s algorithm for mutual exclusion, the impression is given that message
exchange is on the order of square root (N), instead of the more common O(N). (a) What is
fundamentally
different in this algorithm from the others? (b) What problems are caused
by the differences? (Hint: Examine the correctness proof.)
A site can send only one REPLY at a time. A site can send a
REPLY only after it receives a RELEASE for a previous REPLY,
therefore sites lock all of the sites.
The problem that this introduces is that it is prone to deadlock.
4
Download