20 OS Assisted Synchronization

20 OS Assisted Synchronization - CS-350: Fundamentals of...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS-350: Fundamentals of Computing Systems Page 1 of 9Lecture Notes Azer Bestavros. All rights reserved. Reproduction or copying (electronic or otherwise) is expressly forbidden except for students enrolled in CS-350. Concurrency and Synchronization: Basic Primitives and Constructs So far, we have established that hardware approaches relying on disabling interrupts do not solve the mutual exclusion problem in a satisfactory manner: they do not work with multi-processor systems, and even for uni-processor systems, they are not practical, since disabling interrupts is a privilege that we may not want to extend to application programmers. Other Hardware-Assisted Solutions to Mutual Exclusion The issue with our very early attempts at mutual exclusion, using a simple flag to signal availability/unavailability of critical section was due to the fact that a process needs to check such a flag and, if it is available (i.e., it is false), it needed to set it (i.e., it sets it to true). Because there were at least two instructions involved, namely (1) reading/checking the flag, and (2) possibly setting the flag, race conditions were possible, whereby a process would be interrupted after finishing the first step, but before completing the second. Given that disabling interrupts (to prevent that from occurring) is not an acceptable solution (not to mention that it wont work for multi-processor systems), what else could we do? If we can perform both steps in anatomic(i.e., indivisible) fashioni.e., as a single memory access instructionwe would be all set. Indeed, this is the motivation for atomic machine language instructions such as the test-and-set. bool testset(int& i) { if (i==0) { i=1; return true; } else { return false; } } Figure 1 Functionality of a test-and-set() atomic instruction Figure 1 shows the functionality of the hardware test-and-set instruction. It allows a process to atomically (i.e., indivisibly) check if a flag (namely integer i) is 0. If it is, the call to the test-and-set instruction succeeds returning true and the flags value is set to 1. If CS-350: Fundamentals of Computing Systems Page 2 of 9Lecture Notes Azer Bestavros. All rights reserved. Reproduction or copying (electronic or otherwise) is expressly forbidden except for students enrolled in CS-350. it is not, the test-and-set instruction fails returning false and the flags value remains set to 1. Let us now review how this hardware primitive could be used for mutual exclusion. Figure 2 shows such an implementation in which the variable b is used as the flag signifying whether the critical section is available or not. Clearly, since the test-and-set instruction is executed atomically, there is no way a race condition could occur and hence mutual exclusion is guaranteed....
View Full Document

This document was uploaded on 04/14/2011.

Page1 / 9

20 OS Assisted Synchronization - CS-350: Fundamentals of...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online