1 / 8

Operating Systems {week 09}

Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D. Operating Systems {week 09}. A need for synchronization ( i ). Without synchronization amongst processes (and threads), results are unpredictable. how do variables x and y become corrupted?.

lixue
Download Presentation

Operating Systems {week 09}

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. Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D. Operating Systems{week 09}

  2. A need for synchronization (i) • Without synchronization amongst processes (and threads), results are unpredictable how dovariables x and y become corrupted?

  3. A need for synchronization (ii) • Processes compete for resources • Once obtained, the resource isfully dedicated to a process • Often, mutual exclusion is required • No other process is allowed access to the resource • Processes cooperate with other processes • Shared resources • Specific ordering or sequencing of events all of this applies to threads, too!

  4. Critical sections (i) • To synchronize processes(or threads), first identifythe critical sections of code • If process Pi is executing inits critical section, no other process can be executing in their critical sections • A critical section guarantees mutual exclusionto one or more resources

  5. Critical sections (ii) • The operating system must control access to critical sections and guarantee progress: if no process isexecuting in itscritical section process selection cannot be postponed indefinitely (starvation) then and and one or more processeswish to enter theircritical sections process selection must be fair and avoid deadlock

  6. Peterson’s solution • Peterson’s solution is a two-process solution • Processes Pj and Pk share two variables: • Variable turn indicateswhose turn it is toenter the critical section • The flag arrayspecifies if a processis ready to enter itscritical section int turn; boolean flag[2]; // Process Pj while ( true ) { flag[j] = true; // Pjready turn = k; while ( flag[k] && turn == k ) ; // busy wait // CRITICAL SECTION HERE flag[j] = false; }

  7. Producer-Consumer Problem (i) • Model for cooperating processes: • A producer process produces information that is consumed by a consumer process • e.g. client-server, transaction processing, etc. • Implement using a shared memory segment as a shared buffer • Producer adds to the buffer • Consumer empties the buffer

  8. Producer-Consumer Problem (ii) also known as the bounded-buffer problem

More Related