{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

6-synchronization - CSE 3320 Operating Systems Process...

Info icon This preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 3320: Operating Systems Process Synchronization
Image of page 1

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

View Full Document Right Arrow Icon
Background Concurrent access to shared data may lead to data inconsistency Maintaining data consistency requires mechanisms to ensure the orderly execution of cooperating processes Consumer-producer problem (fill all buffers) An integer count (set to 0 initially) keeps track of the number of full buffers. Incremented by the producer after it produces a new item Decremented by the consumer after it consumes an item
Image of page 2
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++; }
Image of page 3

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

View Full Document Right Arrow Icon
Consumer while (1) { while (count == 0) ; // do nothing nextConsumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; count--; /* consume the item in nextConsumed }
Image of page 4
Race Condition count++ and count-- could be implemented as Consider this execution interleaving with “count = 5” initially: S0: producer execute r1 = count S1: producer execute r1 = r1 + 1 S2: consumer execute r2 = count S3: consumer execute r2 = r2 - 1 S4: consumer execute count = r2 S5: producer execute count = r1 r1 = count r1 = r1 + 1 count = r1 r2 = count r2 = r2 - 1 count = r2
Image of page 5

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

View Full Document Right Arrow Icon
Solution to Critical-Section Problem Mutual Exclusion If process Pi is executing in its critical section, then no other processes can be executing in their critical sections • Progress If no process is executing in its critical section and there exist some processes that wish to enter their critical section, then the selection of the processes that will enter the critical section next cannot be postponed indefinitely Bounded Waiting A bound must exist 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 Assume that each process executes at a nonzero speed No assumption concerning relative speed of the N processes
Image of page 6
Peterson’s Solution • Two processes solution Assume that the LOAD and STORE are atomic; that is, cannot be interrupted.
Image of page 7

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

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern