Modified ch5.ppt - Chapter 5 Process Synchronization Operating System Concepts – 9th Edition Silberschatz Galvin and Gagne ©2013 Chapter 5 Process

Modified ch5.ppt - Chapter 5 Process Synchronization...

This preview shows page 1 - 9 out of 74 pages.

Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization
Image of page 1

Subscribe to view the full document.

5.2 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization Background The Critical-Section Problem Peterson’ s Solution Synchronization Hardware Mutex Locks Semaphores Classic Problems of Synchronization Monitors Synchronization Examples Alternative Approaches
Image of page 2
5.3 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Objectives To present the concept of process synchronization. To introduce the critical-section problem, whose solutions can be used to ensure the consistency of shared data To present both software and hardware solutions of the critical-section problem To examine several classical process-synchronization problems To explore several tools that are used to solve process synchronization problems
Image of page 3

Subscribe to view the full document.

5.4 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Background Processes can execute concurrently May be interrupted at any time, partially completing execution Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms to ensure the orderly execution of cooperating processes Illustration of the problem: Suppose that we wanted to provide a solution to the consumer-producer problem that fills all the buffers. We can do so by having an integer counter that keeps track of the number of full buffers. Initially, counter 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.
Image of page 4
5.5 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Bounded-Buffer – Producer-Consumer Problem item next_produced; while (true) { /* produce an item in next produced */ while (((in + 1) % BUFFER_SIZE) == out) ; /* do nothing */ buffer[in] = next_produced; in = (in + 1) % BUFFER_SIZE; } Solution is correct, but can only use BUFFER_SIZE-1 elements item next_consumed; while (true) { while (in == out) ; /* do nothing */ next_consumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; /* consume the item in next consumed */ } Producer Consumer
Image of page 5

Subscribe to view the full document.

5.6 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Producer - Consumer Producer while (true) { /* produce an item in next produced */ while ( counter == BUFFER_SIZE ); // (in + 1) % BUFFER_SIZE) == out // do nothing */ buffer[in] = next_produced; in = (in + 1) % BUFFER_SIZE; counter++; } Consumer while (true) { while ( counter == 0 ); // in == out // do nothing next_consumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; counter--; /* consume the item in next consumed */ }
Image of page 6
5.7 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Consumer while (true) { while (counter == 0) ; /* do nothing */ next_consumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; counter--; /* consume the item in next consumed */ }
Image of page 7

Subscribe to view the full document.

5.8 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Race Condition counter++ could be implemented as register1 = counter register1 = register1 + 1
Image of page 8
Image of page 9
  • Spring '13
  • JAY HEIZER | BARRY RENDER | CHUCK MUNSON

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

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes