13.07.2015 Views

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

258 Concurrency Chapter 8process Aprocess B1 x := 3; x := 5;The resulting value of x can be either 3 or 5, depending on which process finishessecond. If the constants were not small, like 3 and 5, but were so large that several wordswere needed to store them, these assignments might take several machine instructions.The instructions could overlap in such a way that the answer is neither what A intendednor what B intended.We usually assume that certain operations, such as assignment into main store, areatomic and that arbitration takes place at some level within the computer hardware: Iftwo requests arrive simultaneously, they are selected in some sequential order. All ourmethods will depend on hardware arbitration at some level. We will assume that tworequests made simultaneously to main store are serviced consecutively. Such requestscan arise when several computers are connected as a multiprocessor. In uniprocessors,each machine instruction is usually atomic. Traps and interrupts, which can cause a processswitch, are delayed until the current machine instruction is finished. Even here,some long instructions (like block copy) may be interruptible. In addition, missing-pagetraps can occur in the middle of an ordinary instruction.1.1 Mutual exclusionThe problem of mutual exclusion is to ensure that two concurrent activities do notaccess shared data at the same time. As we have seen, arbitration in the hardware is aform of mutual exclusion. We will see how it can be extended to provide exclusion formore complicated operations.Instructions that must be executed while another activity is excluded are groupedinto regions. A region often contains more than one access to the shared data. Forexample, the assignmentx := x + 1must refer to x twice. On some machines, two or more instructions are needed to accomplishthis assignment. They are all part of the same region. Two regions conflict if executionof one requires that the other not be executed at the same time. By definition, allregions conflict with themselves. However, the region just shown would not conflict witha region that increments y instead of x.A typical way to express mutual exclusion is to surround regions by delimiters likeBeginRegion and EndRegion, as shown here.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!