1 / 11

11CS10031 Naman Dasot

Operating Systems 10/2/2014. 11CS10031 Naman Dasot. Topics Covered: Producer Consumer Problem Race Condition Critical Section Problem. Producer Consumer Pg-1. Producer Consumer Problem. It is a classic example of a multi process synchronization problem

cid
Download Presentation

11CS10031 Naman Dasot

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. Operating Systems 10/2/2014 11CS10031Naman Dasot Topics Covered: Producer Consumer Problem Race Condition Critical Section Problem

  2. Producer Consumer Pg-1 Producer Consumer Problem • It is a classic example of a multi process synchronization problem • Both Processes share common fixed-size buffer, used as a queue • The producer's job is to generate a piece of data, put it into the buffer. • Consumer’s job is to consume the piece of data produced by producer, from the buffer. • Consumer should not consume from empty buffer and producer should not produce when buffer is full.

  3. Race Condition Pg-1 Race Condition • It is a behavior of system when output is dependent on the sequence or timing of other uncontrollable event. • Two or more processes are reading or writing some shared data then the final result depends on who runs precisely when.

  4. Critical Section Problem Pg-1 Critical Section Problem • Critical Section: Part of program where shared memory is accessed. Some synchronization technique must be used at the entry and exit of critical section. • Mutual exclusion: • Prohibit more than one process from reading and writing the shared data at the same time

  5. Critical Section Problem Pg-2 Critical Section Problem • Consider system of n processes {p0, p1, … pn-1} • Each process has critical section segment of code • Process may be changing common variables, updating table, writing file, etc • When one process in critical section, no other may be in its critical section • Critical section problem is to design protocol to solve this • Each process must ask permission to enter critical section in entry section, may follow critical section with exit section, then remainder section

  6. Critical Section Problem Pg-3 Critical Section Problem • Entry Section • Ensures safe entry to the critical section. • Critical Section • Uses/modifies shared variable • Exit Section • Informs other processes that the shared variable is now accessible. do { Entry Section critical section Exit Section remainder section } while(true)

  7. Critical Section Problem Pg-4 Solution To Critical Section Problem • Mutual Exclusion: • P0 and P1 can never be in the critical section at the same time Four conditions to provide mutual Exclusion: • No two processes simultaneously in critical region. • No assumptions made about speeds or number of CPUs • No process running outside its critical region may block another process. • No process must wait forever to enter its critical region.

  8. Critical Section Problem Pg-5 Solution To Critical Section Problem • Progress • If no process is executing in its critical section and some processes wish to enter their critical sections, then only those processes that are not executing in their remainder sections can participate in making the decision as to which process will enter its critical section next. This selection cannot be postponed indefinitely.

  9. Critical Section Problem Pg-6 Solution To Critical Section Problem • Bounded waiting •  Bounded waiting means that "there exists a bound or limit 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"

  10. Critical Section Problem Pg-7 Critical Section Problem Mutual exclusion using critical regions

  11. Race condition for Kernel Pg-1 Race Condition for kernel processes • Several Kernel processes try to access shared data structures like • - File descriptor • - Process list (ready queue etc.) • There can be two solutions: • Disable Interrupt : Non-Preemptive • Process cannot be interrupted till its completion. • Busy Waiting: Using lock variable • 0 -> CS is available • 1 -> CS is occupied • Problem: Lock is itself shared

More Related