Concurrent Programming

Concurrent Programming - Operating Systems Structure and...

Info iconThis 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 http://www- dse.doc.ic.ac.uk/concurrency/book_applets/concurrency.html
Background image of page 1

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

View Full DocumentRight 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?
Background 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
Background image of page 3

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

View Full DocumentRight 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
Background 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
Background image of page 5

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

View Full DocumentRight 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.
Background 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
Background image of page 7

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

View Full DocumentRight Arrow Icon
Abstraction Mutual Exclusion Correctness Interleaving Timing
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 74

Concurrent Programming - Operating Systems Structure and...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online