Unformatted text preview:

Before We Begin CSE 120 Principles of Operating Systems Read Chapter 7 Lecture 5 Semaphores IPC Interprocess Communication Monitors Message Passing October 9 2003 Programming Assignment 1 see CSE120 web page Prof Joe Pasquale Due in October 19 Department of Computer Science and Engineering Contact a TA if you need an account University of California San Diego 2003 by Joseph Pasquale Start early 2 1 Cooperating Processes Examples of Cooperating Processes Why structure a computation as cooperative processes Pipeline Performance speed Exploit inherent parallelism of computation Client Server Allow some parts to proceed why others do I O Modularity reusable self contained programs P1 P2 S C Parent Child Each may do a useful task on its own May also be useful as a sub task for others P C1 3 P3 C2 C3 4 Interprocess Communication The Producer Consumer Problem In order to cooperate need to be able to communicate Producer Achieved via IPC interprocess communication ability for a process to communicate with another Interprocess communication requires synchronization Cooperation data from Producer is fed to Consumer How does data get from Producer to Consumer Need mechanisms for each 5 Producer Consumer Shared Memory Producer shared memory int nextin 0 while TRUE buffer nextin N produce nextin Problems Producer process produces data Consumer process consumes data information transfer shared int buffer N Consumer 6 Add Semaphore for Mutual Exclusion shared int buffer N shared sem mutex 1 Consumer int nextout 0 while TRUE consume buffer nextout N How does Consumer wait for Producer nextout Producer Consumer while TRUE while TRUE int nextin 0 Wait mutex int nextout 0 Wait mutex buffer nextin N produce consume buffer nextout N Signal mutex No synchronization only shared memory No mutual exclusion for critical sections nextin Signal mutex nextout Problem still no synchronization 7 8 Add Semaphores for Synchronization shared int buffer N shared sem mutex 1 fullslots 0 emptyslots N Producer Consumer while TRUE while TRUE int nextin 0 Condition variables synchronization Wait mutex buffer nextin N produce consume buffer nextout N Signal fullslots Signal emptyslots Signal mutex Accessed via procedures mutual exclusion Wait fullslots Wait mutex nextin Signal mutex Programming language construct for IPC Variables requiring controlled access shared mem int nextout 0 Wait emptyslots Monitors nextout Works but not easy to understand easily leads to bugs Wait cond Signal cond Only one process can be active inside the monitor active means running or able to run others must wait 9 Producer Consumer Using a Monitor Analogy for Monitors monitor ProducerConsumer condition slotavail itemavail int count 0 nextin 0 nextout 0 buffer N PutItem item GetItem item int item int item if count N Wait slotavail if count 0 Wait itemavail buffer nextin N item item buffer nextout N nextin nextout count count if count 1 Signal itemavail if count N 1 Signal slotavail return item Gate enforces mutual exclusion allows only one process at a time inside monitor Wait cond causes calling process to enter waiting area Signal cond causes a waiting process to re enter active area WAITING AREA 10 ACTIVE Only one active AREA process allowed Producer 11 while TRUE PutItem produce Consumer while TRUE consume GetItem 12 Message Passing Issues with Monitors Given P1 waiting on condition c and P2 signals c now P1 and P2 able to run breaks mutual exclusion one solution signal statements must be at end of monitor procedures Condition variables have no memory send to msg receive from msg P1 P2 kernel Operating system mechanism for IPC Send destination message a signal without someone waiting does nothing Receive source message signal is lost no memory no future effect Data transfer into and out of kernel message buffers Monitors bring structure to IPC Synchronization can t receive until message is sent localizes critical sections and synchronization 13 Producer Consumer Message Passing NO SHARED MEMORY Producer Consumer while TRUE item produce insert msg item Send Consumer msg while TRUE Receive Producer msg item extract msg consume item int item message msg 14 Producer With Flow Control int item message msg empty int item message msg Consumer int item message msg empty do N times Send Producer empty while TRUE Receive Consumer empty item produce insert msg item Send Consumer msg 15 while TRUE Receive Producer msg item extract msg consume item Send Producer empty 16 Producer An Optimization int item message msg Issues with Message Passing Who should messages be addressed to Consumer int item message msg processes or ports mailboxes What if a process wants to receive from anyone do N times Send Producer msg while TRUE item produce Receive Consumer msg insert msg item Send Consumer msg pid receive msg Synchronous blocking vs asynchronous non blocking while TRUE Receive Producer msg item extract msg Send Producer msg consume item typically send is non blocking receive is blocking Kernel buffering how many sends without receives Good paradigm for IPC over networks no shared mem 17 18


View Full Document

UCSD CSE 120 - IPC: Interprocess Communication

Documents in this Course
Threads

Threads

14 pages

Deadlocks

Deadlocks

19 pages

Processes

Processes

14 pages

Paging

Paging

13 pages

Processes

Processes

18 pages

Threads

Threads

29 pages

Security

Security

16 pages

Paging

Paging

13 pages

Processes

Processes

32 pages

Lecture 2

Lecture 2

13 pages

Paging

Paging

8 pages

Threads

Threads

14 pages

Paging

Paging

13 pages

Paging

Paging

26 pages

Paging

Paging

13 pages

Lecture

Lecture

13 pages

Processes

Processes

14 pages

Paging

Paging

13 pages

Security

Security

17 pages

Threads

Threads

15 pages

Processes

Processes

34 pages

Structure

Structure

10 pages

Lecture 3

Lecture 3

13 pages

Lecture 1

Lecture 1

28 pages

Threads

Threads

15 pages

Paging

Paging

30 pages

Load more
Loading Unlocking...
Login

Join to view IPC: Interprocess Communication and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view IPC: Interprocess Communication and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?