1 / 10

Synchronization III: Summary

Explore critical sections, semaphore usage, mutex, atomic instructions, and sequencing events in operating systems for efficient resource access.

dudleym
Download Presentation

Synchronization III: Summary

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Synchronization III:Summary CPE 261403 - Operating Systems http://www.e-cpe.org/moodle

  2. Synchronization Topics • Critical Section • Limiting Concurrent Resource Access • Sequencing Events

  3. int Mutex = 1; while (Mutex == 0); Mutex--; // Critical Section Mutex++; Semaphore Mutex = 1; Wait (Mutex); // Critical Section Signal(Mutex); What’s wrong the code on the left?

  4. Non-Atomic instruction • Register1 = Mutex • Decrease register1 • Mutex = register1 • Register2 = Mutex • Decrease register2 • Mutex = register2 • Register1 = Mutex • Register2 = Mutex • Decrease register2 • Mutex = register2 • Decrease register1 • Mutex = register1

  5. Wait(s) Signal(s) Semaphore

  6. Busy Waiting while (Mutex == 0); Wait (Mutex); Very high CPU load!

  7. Semaphore vs Monitor

  8. Semaphore mutex=1; int count=0; void add() { wait(mutex); count++; signal(mutex); } int count=0; Monitor doStuff { Void add() { count++; } } Critical Section

  9. Semaphore db=3; void connectDb() { wait(db); connect(); signal(db); } int MaxDb=3; Monitor doStuff { Void connectDb() { if (MaxDb > 0){ MaxDb--; connect(); MaxDb++; } } } Limiting Concurrent Resource Access

  10. 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() } } Sequencing Events

More Related