OS_ch06u_F07 - I.-C. Lin, Assistant Professor. Textbook:...

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

View Full Document Right Arrow Icon
I.-C. Lin, Assistant Professor. Textbook: Operating System Principles 7ed CHAPTER 6: 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
odule 6: Synchronization Module 6: ackground ± Background ± The Critical-Section Problem terson Solution ± Peterson s Solution ± Synchronization Hardware emaphores ± Semaphores ± Classic Problems of Synchronization onitors ± Monitors ± Synchronization Examples t i T ti ± Atomic Transactions
Background image of page 2
ackground Background oncurrent access to shared data may result in data ± Concurrent access to shared data may result in data inconsistency aintaining data consistency requires mechanisms to ensure the ± Maintaining data consistency requires mechanisms to ensure the orderly execution of cooperating processes
Background image of page 3

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

View Full DocumentRight Arrow Icon
ackground (cont.) Background (cont.) ± Suppose that we wanted to provide a solution to the consumer- producer problem that fills all the buffers. We can do so by ving an integer unt at keeps track of the number of full having an integer count that keeps track of the number of full buffers. 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.
Background image of page 4
roducer Producer hile (true) while (true) * produce an item and put in nextProduced /p p while (count == BUFFER_SIZE) ; // do nothing buffer [in] = nextProduced; in = (in + 1) % BUFFER_SIZE; count++; }
Background image of page 5

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

View Full DocumentRight Arrow Icon
onsumer Consumer hile (1) while (1) { while (count == 0) () ; // do nothing nextConsumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; count--; /* consume the item in nextConsumed }
Background image of page 6
ce Condition Race Condition unt++ uld be implemented as ± count++ could be implemented as register1 = count register1 = register1 + 1 count = register1 ± count-- could be implemented as register2 = count register2 = register2 - 1 unt = register2 count = register2
Background image of page 7

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

View Full DocumentRight Arrow Icon
ce Condition (cont.) Race Condition (cont.) ± Consider this execution interleaving with count = 5 initially: S0: producer execute register1 = count {register1 = 5} 1: producer execute gister1 = register1 + 1 egister1 = 6} S1: producer execute register1 = register1 + 1 {register1 = 6} S2: consumer execute register2 = count {register2 = 5} S3: consumer execute register2 = register2 - 1 {register2 = 4} 4 d t t = i t 1 t = 6 } S4: producer execute count = register1 {count = 6 } S5: consumer execute count = register2 {count = 4}
Background image of page 8
ce Condition (cont.) Race Condition (cont.) diti ± Race condition ± The situation where several processes access and manipulate shared data concurrently. The final value of the shared data depends upon which yp p process finishes last. ± To prevent race conditions, concurrent processes must be synchronized .
Background image of page 9

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

View Full DocumentRight Arrow Icon
e Critical- ection Problem The Critical Section Problem ± n processes all competing to use some shared data ± Each process has a code segment, called critical section , in which the shared data is accessed. ± Problem ensure that when one process is executing in its critical section, no other process is allowed to execute in its critical section.
Background image of page 10
olution to Critical- ection Problem Solution to Critical Section Problem utual Exclusion 1.
Background image of page 11

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

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

Page1 / 61

OS_ch06u_F07 - I.-C. Lin, Assistant Professor. Textbook:...

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

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