CS201-04 - Benjamin Fenster CS-201(Arslan 14 November 2005...

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

View Full Document Right Arrow Icon
Benjamin Fenster CS-201 (Arslan) 14 November 2005 Notes – Process Synchronization I. Introduction a. If processes share no resources then you can schedule them by any policy that meets the system’s needs. b. When processes share resources, concurrent access to data may cause inconsistency. c. Example i. Have a bounded buffer; one producer, one consumer. ii. Producer waits ‘till the buffer is not full, inserts items at [in % BUFFER_SIZE] iii. Consumer waits until the buffer isn’t empty, removes from [out mod BUFFER_SIZE] iv. ‘counter’ is incremented /decremented as items are inserted / removed 1. In machine language counter++; may be register1 = counter register1 = register1 + 1 counter = register 2. counter--; may be: register2 = counter register2 = register2 – 1 counter = register v. Now there’s a problem! What if the process is interrupted in the middle of those three steps? 1. May have counter = 4, register1 becomes 5 2. Now switch to the consumer process. 3. Counter is still 4, so register2 becomes 3. 4. Store 3 back in counter. 5. Now return to the producer and store 5 back in counter. d. We need a way to describe which parts of a process must be synchronized. e. The example is called a race condition: several processes are accessing the same memory, so the final value depends on whoever gets there first. II. Critical Section a. Assume there are n processes; each has a part that accesses shared data b. That part of the code is called the critical section c. Constraints on an Ideal Solution i. Mutual Exclusion 1. If a process is executing in its critical section, no other process can execute in its critical section. 2. Thus only one process can access the shared data ii. Progress 1. If no process is in its critical section, but one wants to start, it should be allowed. 2. Execution cannot be indefinitely postponed. iii. Bounded Waiting 1. When a process asks to execute in its critical section, there must be a bound for the number of times other processes will execute in their critical sections. 2. There is no assumption about the relative speed of processes – one process may take much longer or shorter. III. Candidate Solutions a. Consider the case with only two processes: p 1 , p 2 i. do { entry section; critical section; exit section; remainder; } while (true); ii. p 1 do { wait (turn != 1); critical section turn = 2
Background image of page 1

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

View Full Document Right Arrow Icon
remainder section
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 6

CS201-04 - Benjamin Fenster CS-201(Arslan 14 November 2005...

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

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