Concurrent Programming

Concurrent Programming - Operating Systems Structure and...

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

View Full Document Right Arrow Icon
Operating Systems Structure and Design Process synchronization critical section problem synchronization hardware semaphores high-level constructs: critical regions, monitors synchronization in Solaris 2 & Windows 2000 http://www- dse.doc.ic.ac.uk/concurrency/book_applets/concurrency.html
Image of page 1

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

View Full Document Right Arrow Icon
Synchronization Problem Threads must share data Data consistency must be maintained Example Suppose my husband wants to withdraw $5 from our account and I want to deposit $10 What should the balance be after the two transactions have been completed? What might happen instead if the two transactions were executed concurrently?
Image of page 2
The balance might be SB – 5 W reads SB I read SB I compute SB + 10 and save new balance W computes SB – 5 and save new balance The balance might be SB + 10 How? Ensure the orderly execution of cooperating threads/processes
Image of page 3

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

View Full Document Right Arrow Icon
Terminology Critical section: a section of code which reads or writes shared data Race condition: potential for interleaved execution of a critical section by multiple threads Results are non-deterministic Mutual exclusion: synchronization mechanism to avoid race conditions by ensuring exclusive execution of critical sections Deadlock: permanent blocking of threads Livelock: execution but no progress Starvation: one or more threads denied resources
Image of page 4
Processes can communicate via shared memory Accessing shared memory leads to race conditions (particularly with preemptive scheduling) Example of race condition? Preventing race conditions 1) Non-preemptive scheduling – processes yield control of CPU only at safe times; OS does not preempt 2) Preemptive scheduling – OS reschedules processes at unpredictable times; processes must protect their critical section with mutual exclusion mechanism
Image of page 5

Info iconThis 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 result in data inconsistency . Maintaining data consistency requires mechanisms to ensure the orderly execution of cooperating processes. Shared memory solution to the bounded-buffer problem allows at most (n-1) items in the buffer at the same time. Paradigm for cooperating processes ; producer process produces information that is consumed by a consumer process. unbounded-buffer places no practical limit on the size of the buffer. bounded-buffer assumes that there is a fixed buffer size.
Image of page 6
Process synchronization as we discussed earlier, processes can cooperate interaction can occur through shared data (e.g., threads) or shared files cooperating processes allow information sharing, computational speedup, modularity, and convenience synchronization is an issue even for uniprocessor systems example: producer-consumer problem two processes: producer and consumer producer generates data and places it in a bounded buffer consumer accesses and uses the data in the buffer the two processes must coordinate access of the shared the buffer keep count of unconsumed data, check to see if empty or full
Image of page 7

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

View Full Document Right Arrow Icon
Abstraction Mutual Exclusion Correctness Interleaving Timing
Image of page 8
Image of page 9
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