Hardware Solutions-Operating Systems-Lecture Notes, Study notes of Operating Systems

Operating Systems is necessary course in Computer Science. Its about threading, process scheduling, deadlocks, memory management etc. This lecture includes: Hardware, Critical, Solution, Boolean, Access, Memory, Location, Swap, Design, Operating

Typology: Study notes

2011/2012

Uploaded on 08/06/2012

sarang
sarang ๐Ÿ‡ฎ๐Ÿ‡ณ

4.5

(47)

86 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
107
Operating Systems [CS-604] Lecture No. 22
Operating Systems
Lecture No. 22
Reading Material
๎˜‚๎˜ƒChapter 7 of the textbook
๎˜‚๎˜ƒLecture 22 on Virtual TV
Summary
๎˜‚๎˜ƒHardware based solutions
๎˜‚๎˜ƒSemaphores
๎˜‚๎˜ƒSemaphore based solutions for the critical section problem
Hardware Solutions
In lecture 21 we started discussing the hardware solutions for the critical section problem.
We discussed two possible solutions but realized that whereas both solutions satisfied the
mutual exclusion and bounded waiting conditions, neither satisfied the progress
condition. We now describe a solution that satisfies all three requirements of a solution to
the critical section problem.
Algorithm 3
In this algorithm, we combine the ideas of the first two algorithms. The common data
structures used by a cooperating process are:
boolean waiting[n];
boolean lock;
The structure of process Pi is:
do
{
waiting[i] = true;
key = true;
while (waiting[i] && key)
key = TestAndSet(lock);
waiting[i] = false;
Critical section
j = (i+1) % n;
while ((j!=i) && !waiting[j])
j = (j+1)% n;
if (j == i)
lock = false;
else
waiting[j] = false;
Remainder section
} while(1);
docsity.com
pf3

Partial preview of the text

Download Hardware Solutions-Operating Systems-Lecture Notes and more Study notes Operating Systems in PDF only on Docsity!

Operating Systems [CS-604] Lecture No. 22

Operating Systems

Lecture No. 22

Reading Material

Chapter 7 of the textbook Lecture 22 on Virtual TV

Summary

Hardware based solutions Semaphores Semaphore based solutions for the critical section problem

Hardware Solutions

In lecture 21 we started discussing the hardware solutions for the critical section problem. We discussed two possible solutions but realized that whereas both solutions satisfied the mutual exclusion and bounded waiting conditions, neither satisfied the progress condition. We now describe a solution that satisfies all three requirements of a solution to the critical section problem.

Algorithm 3

In this algorithm, we combine the ideas of the first two algorithms. The common data structures used by a cooperating process are:

boolean waiting[n]; boolean lock;

The structure of process Pi is: do { waiting[i] = true; key = true; while (waiting[i] && key) key = TestAndSet(lock); waiting[i] = false; Critical section j = (i+1) % n; while ((j!=i) && !waiting[j]) j = (j+1)% n; if (j == i) lock = false; else waiting[j] = false; Remainder section } while(1);

These data structures are initialized to false. To prove that the mutual exclusion requirement is met, we note that process Pi can enter its critical section only if either waiting[i]= = false or key = = false. The value of key can become false only if TestAndSet is executed. The first process to execute the TestAndSet instruction will find key= =false; all others must wait. The variable waiting[i] can only become false if another process leaves its critical section; only one waiting[i] is set to false, maintaining the mutual exclusion requirement. To prove the progress requirement is met, we note that the arguments presented for mutual exclusion also apply here, since a process exiting the critical section either sets lock to false or sets waiting[j] to false. Both allow a process that is waiting to enter its critical section to proceed. To prove that the bounded waiting requirement is met, we note that, when a process leaves its critical section, it scans the array waiting in the cyclic ordering (i+1, i+2, โ€ฆ, n- 1, 0, 1, โ€ฆ, i-1). It designates the first process it sees that is in its entry section with waiting[j]=true as the next one to enter its critical section. Any process waiting to do so will enter its critical section within n-1 turns.

Semaphores

Hardware solutions to synchronization problems are not easy to generalize to more complex problems. To overcome this difficulty we can use a synchronization tool called a semaphore. A semaphore S is an integer variable that, apart from initialization is accessible only through two standard atomic operations: wait and signal. These operations were originally termed P (for wait) and V (for signal). The classical definitions of wait and signal are:

wait(S) { while(S<=0) ;// no op S--; }

signal(S) { S++; }

Modifications to the integer value of the semaphore in the wait and signal operations must be executed indivisibly. That is, when one process is updating the value of a semaphore, other processes cannot simultaneously modify that same semaphore value. In addition, in the case of the wait(S), the testing of the integer value of S (S<=0) and its possible modification (S--) must also be executed without interruption. We can use semaphores to deal with the n-process critical section problem. The n processes share a semaphore, mutex (standing for mutual exclusion) initialized to 1. Each process Pi is organized as follows: