html5-img
1 / 43

INTERPROCESS COMMUNICATION AND SYNCHRONIZATION

INTERPROCESS COMMUNICATION AND SYNCHRONIZATION. Concurrency - Basic Concept. 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).

vea
Download Presentation

INTERPROCESS COMMUNICATION AND SYNCHRONIZATION

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. INTERPROCESS COMMUNICATION AND SYNCHRONIZATION

  2. Concurrency - Basic Concept • 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)

  3. Concurrency - Basic Concept • A simple batch operating system can be viewed as 3 processes : • a reader process • an executor process • a printer process Input Buffer Process Output Buffer

  4. Inter-Process Communication 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.

  5. Inter-Process Communication 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.

  6. Inter-Process Communication 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.

  7. Inter-Process Communication • Critical Resource • Critical Section • Mutual Exclusion

  8. Inter-Process Communication • Critical Resource • It is a resource shared with constraints on its use(e.g., memory, files, printers, etc) • Critical Section • Mutual Exclusion

  9. Inter-Process Communication • Critical Resource • Critical Section • It is code that accesses a critical resource. • Mutual Exclusion

  10. Inter-Process Communication • Critical Resource • Critical Section • Mutual Exclusion • At most one process may be executing a critical section with respect to a particular critical resource simultaneously.

  11. Inter-Process Communication • IPC can be possible in two different ways: • Shared-Memory System • Message-Passing System

  12. Shared-Memory System 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.

  13. Message-Passing System • 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)

  14. Message-Passing System • 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) In order to send and to receive messages, a communication link must exist between the two involved processes.

  15. Message-Passing System • Methods for logically implementing a communication link and the send/receive operations are classified into: • Naming • Buffering

  16. Message-Passing System • Methods for logically implementing a communication link and the send/receive operations are classified into: • Naming • Buffering Consisting of direct and indirect communication.

  17. Message-Passing System • Methods for logically implementing a communication link and the send/receive operations are classified into: • Naming • Buffering Consisting of capacity and message properties.

  18. Direct Communication • 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

  19. Direct Communication • 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 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. Direct Communication • 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.

  21. Direct Communication • 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.

  22. Indirect Communication • 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

  23. Indirect Communication 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.

  24. Indirect Communication • 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

  25. Buffering • 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

  26. Buffering - Capacity 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.

  27. Buffering - Capacity 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.

  28. Buffering - Capacity 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.

  29. Interprocess Synchronization next file to be printed Race Condition Value depends on which of the processes wins the race to update the variable. . . Out = 4 4 abc 5 Prog.c In = 7 6 Process A Prog.n 7 Process B next free slot in the directory . .

  30. Interprocess Synchronization • 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

  31. Interprocess Synchronization • 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.

  32. Interprocess Synchronization • 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.

  33. Critical Section Do { entry section critical section exit section remainder section } while(1); General structure of a typical process

  34. Critical Section Do { entry section critical section exit section remainder section } while(1); General structure of a typical process Section of code that request permission to enter its critical section.

  35. Critical Section Do { entry section critical section exit section remainder section } while(1); General structure of a typical process It is a part of code in which it is necessary to have exclusive access to shared data.

  36. Critical Section Do { entry section critical section exit section remainder section } while(1); General structure of a typical process Code for tasks just after exiting from the critical section.

  37. Critical Section Do { entry section critical section exit section remainder section } while(1); General structure of a typical process The remaining code.

  38. Mutexes : Mutual Exclusion var P1busy, P2busy : boolean; {parent process} P1busy:=false; P2busy:=false; initiate P1, P2; end; {mutex}

  39. Mutexes : Mutual Exclusion var P1busy, P2busy : boolean; 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}

  40. Mutexes : Mutual Exclusion 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} var P1busy, P2busy : boolean; 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}

  41. Critical-Section Problem boolean flag[2]; int turn; do { flag[i] = true; turn = j; while (flag[j] && turn == j); Critical-section flag[i] = false; remainder-section } while(1); Initially flag[0]=flag[1]=false Turn = 0 or 1.

  42. Bakery Algorithm boolean choosing[n]; int number[n]; do { choosing[i] = true; number[i] = max(number[0], number[1], …, number[n-1]) + 1; choosing[i] = flase; for (j=0; j<n; j++){ while (choosing[j]); while((number[j]!=0) && ((number[j],j) < (number[i],j))); } critical-section number[i] = 0; remainder-section } while(1);

  43. Thank You Murugan R Dept. Computer Applications MES College Marampally

More Related