| Issue 9: | 2.10 Exercise 10 | |
| 1 person starred this issue and may be notified of changes. | Back to list |
Exercise 11. Programmers at the Flaky Computer Corporation designed the protocol
shown in Fig. 2.15 to achieve n-threadmutual exclusion. For each question,
either sketch a proof, or display an execution where it fails.
Does this protocol satisfy mutual exclusion?
Is this protocol starvation-free?
is this protocol deadlock-free?
1 class Flaky implements Lock {
2 private int turn;
3 private boolean busy = false;
4 public void lock() {
5 int me = ThreadID.get();
6 do {
7 do {
8 turn = me;
9 } while (busy);
10 busy = true;
11 } while (turn != me);
12 }
13 public void unlock() {
14 busy = false;
15 }
16 }
Figure 2.15 The Flaky lock used in Exercise 11.
Sep 4, 2014
Project Member
#1
sergeypr...@gmail.com
Sep 16, 2014
on first question answer is - *YES* if not: - at least two threads read (busy==false). - then both threads already write (turn=me). - therefore only one thread will read (turn==me) so, on second question your answer is NO, am I right ? and you are right in your answer on the third question :) well done for deeply understanding you can read additional materials like attached one.
Status:
Verified
Sep 18, 2014
2.Yes, it is no deadlock-free. (I forgot to write it) from CHAP5.ppt - I undertand that mutual exclusion - it is "только один поток может быть одновременно в расширяемом ресурсе" - то есть в критической секции. |