Presentation is loading. Please wait.

Presentation is loading. Please wait.

SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally INTERPROCESS COMMUNICATION AND SYNCHRONIZATION SYNCHRONIZATION.

Similar presentations


Presentation on theme: "SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally INTERPROCESS COMMUNICATION AND SYNCHRONIZATION SYNCHRONIZATION."— Presentation transcript:

1 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally INTERPROCESS COMMUNICATION AND SYNCHRONIZATION SYNCHRONIZATION

2 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally In a multi-programming environment, there will be concurrent processes which are of two types: Operating system processes (those that execute system code) User processes (those that execute user’s code) Concurrency - Basic Concept

3 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally A simple batch operating system can be viewed as 3 processes : a reader process an executor process a printer process Concurrency - Basic Concept Input Buffer Output Buffer Process

4 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally Basic Concepts of IPC & Synchronization: In order to cooperate, concurrently executing processes must communicate and synchronize. Interprocess communication is based on the use of shared variables (variables that can be referenced by more than one process) or message passing. Inter-Process Communication

5 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally Basic Concepts of IPC & Synchronization: Synchronization is often necessary when processes communicate. Processes are executed with unpredictable speed. Yet to communicate one process must perform some action such as setting the value of a variable or sending a message that the other detects. This only works if the events perform an action or detect an action are constrained to happen in that order. Thus one can view synchronization as a set of constraints on the ordering of events. The programmer employs a synchronization mechanism to delay execution of a process in order to satisfy such constraints. Inter-Process Communication

6 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally IPC is a capability supported by operating system that allows one process to communicate with another process. The processes can be running on the same computer or on different computers connected through a network. IPC enables one application to control another application, and for several applications to share the same data without interfering with one another. Inter-Process Communication

7 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally Critical Resource Critical Section Mutual Exclusion Inter-Process Communication

8 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally Critical Resource It is a resource shared with constraints on its use(e.g., memory, files, printers, etc) Critical Section Mutual Exclusion Inter-Process Communication

9 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally Critical Resource Critical Section It is code that accesses a critical resource. Mutual Exclusion Inter-Process Communication

10 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally Critical Resource Critical Section Mutual Exclusion At most one process may be executing a critical section with respect to a particular critical resource simultaneously. Inter-Process Communication

11 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally IPC can be possible in two different ways: Shared-Memory System Message-Passing System Inter-Process Communication

12 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally Shared-memory system require communication processes to share some variables. The processes are expected to exchange information through the use of these shared variables. Responsibility for providing communication rests with the application programmer. The OS only needs to provide shared memory. Shared-Memory System

13 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally MPS allow communication processes to exchange messages – responsibility for providing communication rest with OS. The function of a MPS is to allow processes to communicate with each other without the need to resort to shared variables. An IPC facility basically provides two operations: send(message) receive(message) Message-Passing System

14 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally MPS allow communication processes to exchange messages – responsibility for providing communication rest with OS. The function of a MPS is to allow processes to communicate with each other without the need to resort to shared variables. An IPC facility basically provides two operations: send(message) receive(message) Message-Passing System In order to send and to receive messages, a communication link must exist between the two involved processes.

15 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally Methods for logically implementing a communication link and the send/receive operations are classified into: Naming Buffering Message-Passing System

16 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally Methods for logically implementing a communication link and the send/receive operations are classified into: Naming Buffering Message-Passing System Consisting of direct and indirect communication.

17 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally Methods for logically implementing a communication link and the send/receive operations are classified into: Naming Buffering Message-Passing System Consisting of capacity and message properties.

18 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally Each process that wants to communicate must explicitly name the recipient or sender of the communication. In this scheme the send and receive primitives are: send(P, message) – send a message to process P receive(Q, message) – receive a message from process Q Direct Communication

19 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally Each process that wants to communicate must explicitly name the recipient or sender of the communication. In this scheme the send and receive primitives are: send(P, message) – send a message to process P receive(Q, message) – receive a message from process Q Direct Communication Here a link is established automatically between every pair of processes that want to communicate. Exactly one link exists between each pair of processes.

20 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally Symmetry in addressing send(P, message) – send a message to process P receive(Q, message) – receive a message from process Q This scheme shows the symmetry in addressing; that is both the sender and the receiver processes must name the other to communicate. Direct Communication

21 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally Asymmetry in addressing send(P, message) – send a message to process P receive(id, message) – receive a message from any process; the variable id is set to the name of the process with which communication has taken place. Only the sender names the recipient; the recipient is not required to name the sender. Direct Communication

22 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally With indirect communication, the message are sent to and receive from a mailbox. It is an object into which messages may be placed and from which messages may be removed by processes. Each mailbox owns a unique identification. A process may communicate with some other process by a number of different mailboxes. send(A, message) – send a message to mailbox A receive(A, message) – receive a message from mailbox A Indirect Communication

23 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally Mailbox owned by process: Mailboxes may be owned by either by a process or by the system. If the mailbox is owned by a process, then the owner who can only receive from this mailbox and the user who can only send message to the mailbox are to be distinguished. When a process that owns a mailbox terminates, its mailbox disappears. Indirect Communication

24 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally Mailbox owned by the OS: It has an existence of its own, i.e., it is independent and not attached to any particular process. The OS provides a mechanism that allows a process to: create a new mailbox send and receive message through the mailbox destroy a mailbox Indirect Communication

25 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally Whether the communication is direct or indirect, messages exchanged by communicating processes reside in a temporary queue. This queue can be implemented in three ways: Zero capacity Bounded capacity Unbounded capacity Buffering

26 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally Zero capacity The queue has maximum length 0; thus, the link cannot have any messages waiting in it. In this case, the sender must block until the recipient receives the message. The zero-capacity link is referred to as a message-passing system with no buffering. Buffering - Capacity

27 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally Bounded capacity The queue has finite length n; thus, at most n messages can reside in it. If a new message is sent, and the queue is not full, it is placed in the queue either by copying the message or by keeping a pointer to the message and the sender can continue execution without waiting. If the link is full, the sender must block until space is available in the queue. Buffering - Capacity

28 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally Unbounded capacity The queue has potentially infinite length; thus, any number of messages can wait in it. The sender never blocks. Bounded and Unbounded capacity link is referred to as message-passing system with automatic buffering. Buffering - Capacity

29 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally Race Condition Value depends on which of the processes wins the race to update the variable. Interprocess Synchronization abc Prog.c Prog.n.... 4 5 6 7 Process A Process B Out = 4 In = 7 next file to be printed next free slot in the directory

30 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally Serialization Make an operating system not to perform several tasks in parallel. Two strategies to serializing processes in a multitasking environment: The Scheduler can be disabled A Protocol can be introduced Interprocess Synchronization

31 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally The Scheduler can be disabled Scheduler can be disabled for a short period of time, to prevent control being given to another process during a critical action like modifying shared data. Inefficient on multiprocessor machines, since all other processors have to be halted every time one wishes to execute a critical section. Interprocess Synchronization

32 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally A Protocol can be introduced A protocol can be introduced which all programs sharing data must obey. The protocol ensures that processes have to queue up to gain access to shared data. Interprocess Synchronization

33 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally Do { entry section critical section exit section remainder section } while(1); General structure of a typical process Critical Section

34 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally Do { entry section critical section exit section remainder section } while(1); General structure of a typical process Critical Section Section of code that request permission to enter its critical section.

35 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally Do { entry section critical section exit section remainder section } while(1); General structure of a typical process Critical Section It is a part of code in which it is necessary to have exclusive access to shared data.

36 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally Do { entry section critical section exit section remainder section } while(1); General structure of a typical process Critical Section Code for tasks just after exiting from the critical section.

37 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally Do { entry section critical section exit section remainder section } while(1); General structure of a typical process Critical Section The remaining code.

38 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally Mutexes : Mutual Exclusion {parent process} P1busy:=false; P2busy:=false; initiate P1, P2; end; {mutex} var P1busy, P2busy : boolean;

39 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally Mutexes : Mutual Exclusion process P1 begin while true do begin P1busy := true; while P2busy do {keep testing}; critical-section; P1busy:=false; other_P1busy_processing; end{while} End; {P1} {parent process} P1busy:=false; P2busy:=false; initiate P1, P2; end; {mutex} var P1busy, P2busy : boolean;

40 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally Mutexes : Mutual Exclusion process P1 begin while true do begin P1busy := true; while P2busy do {keep testing}; critical-section; P1busy:=false; other_P1busy_processing; end{while} End; {P1} process P2 begin while true do begin P2busy := true; while P1busy do {keep testing}; critical-section; P2busy:=false; other_P2busy_processing; end{while} End; {P2} {parent process} P1busy:=false; P2busy:=false; initiate P1, P2; end; {mutex} var P1busy, P2busy : boolean;

41 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally Critical-Section Problem boolean flag[2]; int turn; do { flag[i] = true; flag[i] = true; turn = j; turn = j; while (flag[j] && turn == j); while (flag[j] && turn == j); Critical-section Critical-section flag[i] = false; flag[i] = false; remainder-section remainder-section } while(1); } while(1); Initially flag[0]=flag[1]=false Turn = 0 or 1.

42 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally Bakery Algorithm boolean choosing[n]; int number[n]; do { choosing[i] = true; choosing[i] = true; number[i] = max(number[0], number[1], …, number[n-1]) + 1; number[i] = max(number[0], number[1], …, number[n-1]) + 1; choosing[i] = flase; choosing[i] = flase; for (j=0; j<n; j++){ for (j=0; j<n; j++){ while (choosing[j]); while (choosing[j]); while((number[j]!=0) && ((number[j],j) < (number[i],j))); while((number[j]!=0) && ((number[j],j) < (number[i],j))); } critical-section critical-section number[i] = 0; number[i] = 0; remainder-section remainder-section } while(1); } while(1);

43 SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally Thank You Murugan R Dept. Computer Applications MES College Marampally


Download ppt "SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally INTERPROCESS COMMUNICATION AND SYNCHRONIZATION SYNCHRONIZATION."

Similar presentations


Ads by Google