1 / 22

Interprocess Communication

Process Communication Issues. How do we pass information between processes?How do we ensure the processes do not get in each others way during critical activities?Proper sequencing when processes have dependencies upon each other.. Race Conditions/Shared Data Problem. Consider the example in the b

brayton
Download Presentation

Interprocess Communication

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 Processes/threads often work together to accomplish some task. This usually means that the processes/threads need to communicate.

    2. Process Communication Issues How do we pass information between processes? How do we ensure the processes do not get in each others way during critical activities? Proper sequencing when processes have dependencies upon each other.

    3. Race Conditions/Shared Data Problem Consider the example in the book of a print spooler. When a process wants to print a file, it enters the name in the spooler directory. Another process periodically checks to see if there are any files to be printed, if so, prints them and removes their file names from the spooler directory.

    4. Printer Spooler/Race Condition

    5. Avoiding Race Conditions Accessing the shared memory should be mutually exclusive to one process at a time. This shared memory area is known as a critical section.

    6. Conditions for Parallel Process to cooperate correctly and efficiently using shared data No two processes simultaneously in critical section No assumptions made about speeds or numbers of CPUs No process running outside its critical region may block another process No process must wait forever to enter its critical region

    7. What we would like to happen

    8. Easy Approach – Disable Interrupts Disable Interrupts before accessing critical section and then re-enable afterwards Ensures the process will not be interrupted while accessing the shared memory Can be problematic if the process does not re-enable interrupts Better mechanisms for mutual exclusion

    9. Using a Lock Variable Use variable called lock to indicate if a critical section is currently being accessed If lock is set then wait… otherwise enter critical section What happens if a process is interrupted from running just after reading the lock is not set?

    10. Atomic Instructions Atomic instructions are those that are performed together and are considered indivisible. As we just saw performing a test on the lock is not guaranteed to “complete” before another process is scheduled. if (lock == 0) lock = 1; enter critical section The C style code translates to many assembly instructions Another process could be scheduled after executing any of these assembly (ie the read of lock)

    11. Strict Alternation Proposed solution to critical region problem (a) Process 0. (b) Process 1.

    12. Strict Alternation So, what happens when Process 1 is slow in executing? Process 0 eventually is blocked waiting on Process 1 to complete it’s noncritical section. This violates our condition of no process running outside its critical region may block another process

    13. Peterson’s Solution

    15. Is Peterson’s solution correct? It is correct in terms of our four conditions for parallel processes to cooperate correctly and efficiently using shared data but it requires busy waiting if the process cannot enter the critical section.

    16. Priority Inversion

    17. Prevent Busy Waiting with Blocking Calls Sleep – Causes the caller to suspend until another process wakes it up. Wakeup – wakeups specified process

    18. Producer-Consumer using sleep and wakeup

    19. How do we fix this problem? Add a bit to indicate if a process is already awake and check it before issuing a sleep? Obviously we need a mechanism to keep count of saved “wakeups”

    20. Semaphore Semaphores introduced to keep track of “wakeups”. Dijkstra proposed the semaphore have two operations down – checks if Semaphore >0, if so it decrements the count. Otherwise sleep. up – simply increments semaphore count and if a process was sleeping on a down it obtains semaphore and completes down operation. up and down are atomic instructions

    21. Producer-Consumer with Semaphores

    22. Semaphores Uses To provide mutual exclusion to a shared resource. Obviously, we can imagine the count of semaphore corresponding to the number of shared identical resources. To provide synchronization full and empty were used in this way

More Related