6-synchronization - CSE 3320 Operating Systems Process Synchronization Background Concurrent access to shared data may lead to data inconsistency

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

View Full Document Right Arrow Icon
CSE 3320: Operating Systems Process Synchronization
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background Concurrent access to shared data may lead to data inconsistency Maintaining data consistency requires mechanisms to ensure the orderly execution of cooperating processes Consumer-producer problem (Fll all buffers) An integer count (set to 0 initially) keeps track of the number of full buffers. Incremented by the producer after it produces a new item Decremented by the consumer after it consumes an item
Background image of page 2
Producer while (true) { // produce an item and put in nextProduced w h i l e ( c o u n t = = B U F F E R _ S I Z E ) ; // do nothing buffer [in] = nextProduced; i n = ( i n + 1 ) % B U F F E R _ S I Z E ; c o u n t + + ; }
Background image of page 3

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

View Full DocumentRight Arrow Icon
Consumer while (1) { w h i l e ( c o u n t = = 0 ) ; // do nothing nextConsumed = buffer[out]; o u t = ( o u t + 1 ) % B U F F E R _ S I Z E ; c o u n t - - ; /* consume the item in nextConsumed }
Background image of page 4
Race Condition • count++ and count-- could be implemented as • Consider this execution interleaving with “count = 5” initially: S0: producer execute r1 = count S1: producer execute r1 = r1 + 1 S2: consumer execute r2 = count S3: consumer execute r2 = r2 - 1 S4: consumer execute count = r2 S5: producer execute count = r1 r1 = count r1 = r1 + 1 count = r1 r2 = count r2 = r2 - 1 count = r2
Background image of page 5

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

View Full DocumentRight Arrow Icon
Solution to Critical-Section Problem Mutual Exclusion If process Pi is executing in its critical section, then no other processes can be executing in their critical sections Progress If no process is executing in its critical section and there exist some processes that wish to enter their critical section, then the selection of the processes that will enter the critical section next cannot be postponed indeFnitely Bounded Waiting A bound must exist on the number of times that other processes are allowed to enter their critical sections after a process has made a request to enter its critical section and before that request is granted Assume that each process executes at a nonzero speed No assumption concerning relative speed of the N processes
Background image of page 6
Peterson’s Solution • Two processes solution Assume that the LOAD and STORE are atomic; that is, cannot be interrupted. • The two processes share two variables:
Background image of page 7

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

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

This note was uploaded on 01/18/2012 for the course INFORMATIK 2011 taught by Professor Phanthuongcang during the Winter '11 term at Cornell University (Engineering School).

Page1 / 33

6-synchronization - CSE 3320 Operating Systems Process Synchronization Background Concurrent access to shared data may lead to data inconsistency

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

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