08_Process_Synchronization_I_2spp

08_Process_Synchronization_I_2spp - CSC 4103 - Operating...

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

View Full Document Right Arrow Icon
1 CSC 4103 - Operating Systems Fall 2009 Tevfik Ko ! ar Louisiana State University September 17 th , 2009 Lecture - VIII Process Synchronization - I 2 Roadmap • Process Synchronization • Race Conditions • Critical-Section Problem Solutions to Critical Section Different Implementations
Background image of page 1

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

View Full DocumentRight Arrow Icon
3 Background • Concurrent access to shared data may result in data inconsistency • Maintaining data consistency requires mechanisms to ensure the orderly execution of cooperating processes • Consider consumer-producer problem: Initially, count is set to 0 It is incremented by the producer after it produces a new buffer and is decremented by the consumer after it consumes a buffer. 4 Producer: while (true){ /* produce an item and put in nextProduced while (count == BUFFER_SIZE) ; // do nothing buffer [in] = nextProduced; in = (in + 1) % BUFFER_SIZE; count++; } while (1) { while (count == 0) ; // do nothing nextConsumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; count--; } /* consume the item in nextConsumed Consumer: Shared Variables: count=0, buffer[]
Background image of page 2
Race Condition ! Race condition : The situation where several processes access and manipulate shared data concurrently. The final value of the shared data depends upon which process finishes last. ! To prevent race conditions, concurrent processes must be synchronized. Ensure that only one process at a time is manipulating the variable counter . ! The statements • counter++; • counter--; must be performed atomically . ! Atomic operation means an operation without interruption. 5 6 Race Condition count++ could be implemented as register1 = count register1 = register1 + 1 count = register1 count-- could be implemented as register2 = count register2 = register2 - 1 count = register2 Consider this execution interleaving with “count = 5” initially: S0: producer execute register1 = count {register1 = 5} S1: producer execute register1 = register1 + 1 {register1 = 6} S2: consumer execute register2 = count {register2 = 5} S3: consumer execute
Background image of page 3

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

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

Page1 / 10

08_Process_Synchronization_I_2spp - CSC 4103 - Operating...

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

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