Presentation is loading. Please wait.

Presentation is loading. Please wait.

6/16/2015 Chapter Eight Process Synchronisation. Index Objectives Concurrent processes and Asynchronous concurrent processes Process synchronisation Mutual.

Similar presentations


Presentation on theme: "6/16/2015 Chapter Eight Process Synchronisation. Index Objectives Concurrent processes and Asynchronous concurrent processes Process synchronisation Mutual."— Presentation transcript:

1 6/16/2015 Chapter Eight Process Synchronisation

2 Index Objectives Concurrent processes and Asynchronous concurrent processes Process synchronisation Mutual exclusion

3 Index Terminology Critical Section –when it is accessing shared data in a system. Semaphore –Used to implement the idea of mutual exclusion due to multiple access Concurrent process –Processes are said to be concurrent if they exist at the same time.

4 Index Software implementation Idea of process synchronization While gate = closed : DO null operation (gate is open) gate := closed : so that other cannot use it ……….. Critical section ………. gate := open : let other to use it Above is impractical for multi- processes

5 Index Process Type Concurrent processes –processes exist at the same time –if on a single CPU system, then context switching are required Asynchronous concurrent processes –concurrent processes function independently –require occasional synchronization or interprocess communication

6 Index Asymmetric and Symmetric Processing

7 Index Mutual Exclusion To ensure the integrity of data, shared data cannot be used by more than ONE process at the same time Otherwsie data will be updated incorrectly

8 Index Critical Sections When a process is accessing shared modifiable data, it is in “Critical Section”

9 Index Features of Critical Sections when a process is in the critical section, other processes may continue execution outside the critical region. when a process leaves its critical section, one other process waiting to enter the critical section may proceed. Mutual exclusion can be implemented by means of SEMAPHORES.

10 Index Synchronization A process may not be able to continue until a service is provided. It involves the signaling between two or more processes. Process synchronization can be achieved by semaphores.

11 Index Process Synchronization

12 Index Two processes Compilation

13 Index Semaphore Semaphore was introduced by Dijksta in 1965. A semaphore is a protected variable S. The value can be accessed and altered by three operations, namely, wait (P(S)), signal (V(S)) and initialization operations only.

14 Index Characteristics of semaphores Binary semaphores can assume only the value 0 or 1 Counting semaphores can assume only non-negative integer values P(S) and V(S) are the initial Dutch words. P(S) refers to wait; while V(S) is signal.

15 Index Code for binary semaphore P operation on variable S, P(S) is if S > 0 then S := S - 1 (means no process is using) Else (wait on S to change value) V operation (V means to signify), V(S) is If (one or more processes is/are waiting on S to change.) then (let one of theses processes proceed ) else S:= S + 1 (no process in the semaphore queue)

16 Index Two-process synchonization

17 Index Software Example Program example-one var active: semaphore; Procedure process-A begin while true do begin P(active); critical-sec; : V(active); : end end; Procedure process-B begin while true do begin : P(active); critical-sec; : V(active); : end end;

18 Index Software Example (Continue…) Begin semaphore-init(active,1); /* initialise the semaphore variable active */ parbegin process-A; process-B; parend end.

19 Index Mutual Exclusion When a resource can be accessed by at least two processes, it can only be exclusively used by one of them until it is completed. In a system providing multiple processes, it is desirable to co- ordinate the activities of them The relationship can be described by a set of processes called producer- consumer.

20 Index Producer and Consumer

21 Index Implementation for mutual exclusion Dekker’s Primitives Interrupt masking locks

22 Index Example for Mutual Exclusion Procedure producer While true do {.... produce an item.... P(empty); P(mutex);.... add item to buffer;.... V(mutex); V(full); } Procedure consumer While true do { P(full); P(mutex);.... remove an item from buffer to “local”.... V(mutex); V(empty);.... consume the item in “local” }

23 Index Summary Process synchronisation used to solve synchronisation by semaphore. Those waiting to be served is at semaphore queue. To avoid deadlock, processes should ensure that the resources are exclusively used Producer and consumer model is used for mutual exclusion.


Download ppt "6/16/2015 Chapter Eight Process Synchronisation. Index Objectives Concurrent processes and Asynchronous concurrent processes Process synchronisation Mutual."

Similar presentations


Ads by Google