1 / 14

CMT603

CMT603. Lecture 6 Process Interaction-2. Recap. Critical Section problem Caused by preemptive scheduling These days also caused by concurrent processing on multi CPU machines. Contents. OS solutions Semaphores Uses Classical problem. Semaphores. An Integer – ‘S’ Two atomic operations

drew
Download Presentation

CMT603

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. CMT603 Lecture 6 Process Interaction-2

  2. Recap • Critical Section problem • Caused by preemptive scheduling • These days also caused by concurrent processing on multi CPU machines

  3. Contents • OS solutions • Semaphores • Uses • Classical problem

  4. Semaphores • An Integer – ‘S’ • Two atomic operations • Acquire (s) • Many names • P() - ‘proberen’ (to test) • Wait() • Release (s) • V() -’verhogen’ (to increment) • Signal()

  5. Classical Semaphore Operations Acquire (S) while ( S <=0 ) {wait} S--; Release(S) S++; • Busy wait • No fair ordering for waiting processes

  6. Fair Semaphore Operations • Semaphore has • An Integer – ‘S’ • An associated queue Acquire (S) S--; If (S < 0 ){ add process to queue and block process } Release (S) S++; If (S<= 0) { remove process from queue and wakeup the process }

  7. Uses of Semaphores • The value of a mutex lock semaphore is less than or equals to 1. • It is used to control access to the critical section for a process • The value of a counting semaphore can range over an unrestricted domain • It is used to control access to a given resource consisting a finite number of instances

  8. Critical Section SolutionUsing Semaphores Acquire (S) S--; If (S < 0 ){ add process to queue and block process } Release (S) S++; If (S<= 0) { remove process from queue and wakeup the process } Process 1 acquire (S); Critical section; release (S); Process 2 acquire (S); Critical section; release (S); Look up Edsger Dijkstra

  9. Multiple Resource Instances • A resource with 3 instances • Initialise s = 3 Process n acquire (S); Critical section; release (S);

  10. The Bounded-Buffer Problem(A Classic) • Producer and Consumer Problem • Assume we have a bounded-buffer with fixed size of N. The producer adds items to the buffer and the consumer takes items from the buffer out in Count 1 2 3 N-2 N-1

  11. A Solution Using Semaphores • EmptyBuffers • FullBuffers • Mutex Producer acquire(emptyBuffers) acquire(mutex) add an item to the buffer pool release(mutex) release(fullBuffers) Consumer acquire(fullBuffers) acquire(mutex) remove item from buffer pool release(mutex) release(emptyBuffers)

  12. An Example Consumer acquire(fullBuffers) acquire(mutex) remove item from buffer pool release(mutex) release(emptyBuffers) Producer acquire(emptyBuffers) acquire(mutex) add an item to the buffer pool release(mutex) release(fullBuffers) • fullBuffers • emptyBuffers • mutex

  13. Summary OS solutions • Semaphores • Uses • Classical problem • P.S. Assembly language CW due Week 11 in this lecture. • & Matt may be a bit late for lab 15:10.

  14. Next lecture • Multiple resources Process n acquire (R1); acquire (R2); Critical section; release (R2); release (R1);

More Related