2
236 Chapter 7 Process Synchronization If a system crash occurs, the information in the log is used in restoring the state of the updated data items, which is accomplished with the use of the undo and redooperations. To reduce the overhead in searching the log after a system failure has occurred, we can use a checkpoint scheme. When several transactions overlap their execution, the resulting execution may no longer be equivalent to an execution where these transactions executed atomically. To ensure correct execution, we must use a concurrency-control scheme to guarantee serializability. There are various different concurrency- control schemes that ensure serializability by either delaying an operation or aborting the transaction that issued the operation. The most common ones are locking protocols and timestamp-ordering schemes. . Exercises 7.1 What is the meaning of the term busy waiting? What other kinds of waiting are there in an operating system? Can busy waiting be avoided altogether? Explain your answer. 7.2 Explain why spinlocks are not appropriate for uniprocessor systems yet may be suitable for multiprocessor systems. ~ Prove that, in the bakery algorithm (Section 7.2.2), the following property ~ holds: If Pi is in its critical section and Pk (k =Ii) has already chosen its number [k] =I 0, then (number [i], i) < (number [k], k). ~ The first known correct software solution to the critical-section problem ~ for two processes was developed by Dekker. The two processes, Po and PIt share the following variables: Fig\] boolean flag[2]; /* initially false */ int turn; All thE immat. Figure Pro1 section 7.6 In SecD the sy~ minim I, The structure of process Pi (i ==0 or 1), with Pj (j == 1 or 0) being the other process, is shown in Figure 7.27. ~ Prove that the algorithm satisfies all tliw.i8e requirements for the critical- section problem. 7.5 The first known correct software solution to the critical-section problem for n processes with a lower bound on waiting of n - 1 turns was pre- sented by Eisenberg and McGuire. The processes share the following variables: enum pst ate {idle, want_in, in_cs}; pstate flag en] ; int turn; 7.7 Show t then m 6' The 51 with n no cusl the bar shop. I in bne ( barber. 7.9 The Ci process cigareti . I:

236 Chapter 7 Process Synchronizationjwang3/CMSC312/Wang 10-11-07.pdfThe Sleeping-Barber Problem. A barbershop consists of a waiting room with n chairs and the barber room contaUning

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 236 Chapter 7 Process Synchronizationjwang3/CMSC312/Wang 10-11-07.pdfThe Sleeping-Barber Problem. A barbershop consists of a waiting room with n chairs and the barber room contaUning

236 Chapter 7 Process Synchronization

If a system crash occurs, the information in the log is used in restoring the stateof the updated data items, which is accomplished with the use of the undo andredooperations. To reduce the overhead in searching the log after a systemfailure has occurred, we can use a checkpoint scheme.

When several transactions overlap their execution, the resulting executionmay no longer be equivalent to an execution where these transactions executedatomically. To ensure correct execution, we must use a concurrency-controlscheme to guarantee serializability. There are various different concurrency-control schemes that ensure serializability by either delaying an operation oraborting the transaction that issued the operation. The most common ones arelocking protocols and timestamp-ordering schemes.

. Exercises

7.1 What is the meaning of the term busy waiting? What other kinds of waitingare there in an operating system? Can busy waiting be avoided altogether?Explain your answer.

7.2 Explain why spinlocks are not appropriate for uniprocessor systems yetmay be suitable for multiprocessor systems.

~ Prove that, in the bakery algorithm (Section 7.2.2), the following property~ holds: If Pi is in its critical section and Pk (k =Ii) has already chosen itsnumber [k] =I0, then (number [i], i) < (number [k], k).

~ The first known correct software solution to the critical-section problem~ for two processes was developed by Dekker. The two processes, Po and

PIt share the following variables:

Fig\]

boolean flag[2]; /* initially false */int turn;

All thEimmat.

FigurePro1

section

7.6 In SecD

the sy~minim

I,

The structure of process Pi (i ==0 or 1), with Pj (j == 1 or 0) being theother process, is shown in Figure 7.27. ~

Prove that the algorithm satisfies all tliw.i8erequirements for the critical-section problem.

7.5 The first known correct software solution to the critical-section problemfor n processes with a lower bound on waiting of n - 1 turns was pre-sented by Eisenberg and McGuire. The processes share the followingvariables:

enum pst ate {idle, want_in, in_cs};

pstate flag en] ;

int turn;

7.7 Show tthen m

6' The 51.with nno cuslthe bar

shop. Iin bne (barber.

7.9 The Ciprocesscigareti

.I:

Page 2: 236 Chapter 7 Process Synchronizationjwang3/CMSC312/Wang 10-11-07.pdfThe Sleeping-Barber Problem. A barbershop consists of a waiting room with n chairs and the barber room contaUning

Exercises 237

(ted

En

do {

flag[i] = true;

while (flag[j]) {if (turn == j) {

flag [i] = false;

while (turn == j);

flag[i] = true;

}}

critical section

turn = j;

flag [i] = false;g

:er? remaUndersection

yet } while (1);

rtyits

Figure 7.27 The structure of process Pi UnDekker's algorithm.

Lical-

All the elements of flag are initially idle; the initial value of turn is

immaterial (between 0 and n-l). The structure of process Pi is shown inFigure 7.28.

Prove that the algorithm satisfies all three requirements for the critical-section problem.

-7.6 In Section 7.3, we mentioned that disabling Unterrupts frequently can affectthe system's clock. Explain why it can, and how such effects can beminimized.

7.7 Show that, if the wai t and signaloperations are not executed atomically,then mutual exclusion may be violated.

& The Sleeping-Barber Problem. A barbershop consists of a waiting roomwith n chairs and the barber room contaUning the barber chair. If there areno customers to be served, the barber goes to sleep. If a customer entersthe barbershop and all chairs are occupied, then the customer leaves theshop. If the barber is busy but chairs are available, then the customer sitsin one of the free chairs. If the barber is asleep, the customer wakes up thebarber. Write a program to coordinate the barber and the customers.

7.9 The Cigarette-Smokers Problem. Consider a system with three smokerprocesses and one agent process. Each smoker continuously rolls acigarette and then smokes it. But to roll and smoke a cigarette, the smoker I.

emland

Jthe

t:>lem'pre-wUng