Process Synchronization I Nov 27, 2007 CPE 261403 - Operating Systems [email protected].
Synchronization III: Summary CPE 261403 - Operating Systems .
-
Upload
pearl-hunt -
Category
Documents
-
view
215 -
download
0
Transcript of Synchronization III: Summary CPE 261403 - Operating Systems .
![Page 1: Synchronization III: Summary CPE 261403 - Operating Systems .](https://reader036.fdocuments.us/reader036/viewer/2022081813/5697bfc41a28abf838ca5ab9/html5/thumbnails/1.jpg)
Synchronization III:Summary
CPE 261403 - Operating Systemshttp://www.e-cpe.org/moodle
![Page 2: Synchronization III: Summary CPE 261403 - Operating Systems .](https://reader036.fdocuments.us/reader036/viewer/2022081813/5697bfc41a28abf838ca5ab9/html5/thumbnails/2.jpg)
Synchronization Topics
Critical Section
Limiting Concurrent Resource Access
Sequencing Events
![Page 3: Synchronization III: Summary CPE 261403 - Operating Systems .](https://reader036.fdocuments.us/reader036/viewer/2022081813/5697bfc41a28abf838ca5ab9/html5/thumbnails/3.jpg)
What’s wrong the code on the left?int Mutex = 1;
while (Mutex == 0);
Mutex--;
// Critical Section
Mutex++;
Semaphore Mutex = 1;
Wait (Mutex);
// Critical Section
Signal(Mutex);
![Page 4: Synchronization III: Summary CPE 261403 - Operating Systems .](https://reader036.fdocuments.us/reader036/viewer/2022081813/5697bfc41a28abf838ca5ab9/html5/thumbnails/4.jpg)
Non-Atomic instruction
Register1 = MutexDecrease register1Mutex = register1
Register2 = MutexDecrease register2Mutex = register2
Register1 = MutexRegister2 = MutexDecrease register2Mutex = register2Decrease register1Mutex = register1
![Page 5: Synchronization III: Summary CPE 261403 - Operating Systems .](https://reader036.fdocuments.us/reader036/viewer/2022081813/5697bfc41a28abf838ca5ab9/html5/thumbnails/5.jpg)
Semaphore
Wait(s) Signal(s)
![Page 6: Synchronization III: Summary CPE 261403 - Operating Systems .](https://reader036.fdocuments.us/reader036/viewer/2022081813/5697bfc41a28abf838ca5ab9/html5/thumbnails/6.jpg)
Busy Waiting
while (Mutex == 0); Wait (Mutex);
Very high CPU load!
![Page 7: Synchronization III: Summary CPE 261403 - Operating Systems .](https://reader036.fdocuments.us/reader036/viewer/2022081813/5697bfc41a28abf838ca5ab9/html5/thumbnails/7.jpg)
Semaphore vs Monitor
![Page 8: Synchronization III: Summary CPE 261403 - Operating Systems .](https://reader036.fdocuments.us/reader036/viewer/2022081813/5697bfc41a28abf838ca5ab9/html5/thumbnails/8.jpg)
Critical Section
Semaphore mutex=1;
int count=0;
void add() {
wait(mutex);
count++;
signal(mutex);
}
int count=0;
Monitor doStuff {
Void add() {
count++;
}
}
![Page 9: Synchronization III: Summary CPE 261403 - Operating Systems .](https://reader036.fdocuments.us/reader036/viewer/2022081813/5697bfc41a28abf838ca5ab9/html5/thumbnails/9.jpg)
Limiting Concurrent Resource AccessSemaphore db=3;
void connectDb() {
wait(db);
connect();
signal(db);
}
int MaxDb=3;
Monitor doStuff {
Void connectDb() {
if (MaxDb > 0){
MaxDb--;
connect();
MaxDb++;
}
}
}
![Page 10: Synchronization III: Summary CPE 261403 - Operating Systems .](https://reader036.fdocuments.us/reader036/viewer/2022081813/5697bfc41a28abf838ca5ab9/html5/thumbnails/10.jpg)
Sequencing Events
Semaphore buffer=0;
void consume() {wait(buffer);
removeItem();}
Void Produce() {addItem();signal(buffer);
}
Monitor doStuff {
Condition buffer;
Void consume() { if (bufferLen==0)
buffer.wait(); removeItem();}
Void Produce() { addItem(); buffer.signal()}
}