370 likes | 456 Views
Operating Systems. Exam 2 today can use single sheet. Sassn4 - due 1 Nov wassn6 - e/c 25 Oct. Concurrent Processes. IV. Parallel Processing. multi-tasking only simulates concurrency by interleaving execution. Concurrent Processes. Parallel Processing is true concurrency
E N D
Operating Systems Exam 2 today can use single sheet Sassn4 - due 1 Nov wassn6 - e/c 25 Oct
Concurrent Processes IV. Parallel Processing multi-tasking only simulates concurrency by interleaving execution
Concurrent Processes Parallel Processing is true concurrency (“at the same time”)
Concurrent Processes E. Process Synchronization manage competition control access to a “critical region”
Operating Systems signs on the “critical region”
Concurrent Processes manage competition analogy: raising hands in class
Concurrent Processes Without process synchronization “bad things” can happen … eg, the “missed waiting customer”
Concurrent Processes example:
Concurrent Processes your number is called clerk is interrupted next clerk advances # you’re missed!
Concurrent Processes “race condition” two people access same ATM account and deposit money …
Concurrent Processes E. Process Synchronization semaphores
Concurrent Processes semaphores “signals” when a resource is available
Concurrent Processes semaphores ensure mutual exclusion to the critical code regions with test & increment
Concurrent Processes semaphores P - test before using resource V - incrementwhen releasing
Concurrent Processes semaphores P - test P(s): if s > 0 s-- V - increment V(s): s++
Concurrent Processes P & V are executed by the OS in response to a process’ request for a resource If semaphore=0, then process must wait If semaphore>0, then can use the resource
Concurrent Processes example: use the printer semaphore_prn := 1 // available P(semaphore_prn) // one cycle if > 0 s-- and allow to use finished with printer V(semaphore_prn) // one cycle s++
Concurrent Processes control access to a “critical region” key: determine what is the critical region (what code)
Concurrent Processes F. Process Cooperation two processes knowingly cooperate
Concurrent Processes requires mutual exclusion and synchronization implement with semaphores
Concurrent Processes 1. producers and consumers speed and synchronization problems possible
Streaming Audio server client Buffer Producer Consumer ideal situation - processes are synchronized
Streaming Audio server client Buffer Producer Consumer bad situation - buffer overrun
Streaming Audio Because buffer holds finite amount of data, synchronization process must delay producer from generating more data when buffer is full.
Producers and Consumers : One Process Produces Some Data that Another Process Consumes Later. Buffer Producer Consumer Buffer Producer Consumer Buffer Producer Consumer
Streaming Audio server client Buffer Producer Consumer bad situation - empty buffer
Streaming Audio Because buffer is empty must delay consumer from retrieving data
Streaming Audio This synchronization task can be implemented by 3 semaphores: - Indicate number of full positions in buffer. - Indicate number of empty positions in buffer. - Mutex, will ensure mutual exclusion between processes
Indicate number of full positions in buffer. • Indicate number of empty positions in buffer. • Mutex, will ensure mutual exclusion between processes
Concurrent Processes G. Concurrent Programming 1. explicit parallelism
Concurrent Processes programmer must indicate what can done in parallel example: COBEGIN and COEND stmts
Concurrent Processes fParabola = 3*x^2 + 15*x – 7; COBEGIN temp1 = x^2; // performed by processor 1 concurrently temp2 = 15*x; // performed by processor 2 concurrently COEND
Concurrent Processes G. Concurrent Programming 2. implicit parallelism
Concurrent Processes compiler determines parallelism difficult job :-)
Exam #2 here it comes … have a nice day :-)