1 / 39

Process concurrency

Process concurrency. G.Anuradha Reference: William Stallings. Contents. • Principles of concurrency • Mutual Exclusion-hardware approaches • Mutual Exclusion-software support • Semaphores • Monitors • Message Passing • Readers/Writers problem • Deadlock and starvation

rodney
Download Presentation

Process concurrency

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. Process concurrency G.Anuradha Reference: William Stallings

  2. Contents • Principles of concurrency • Mutual Exclusion-hardware approaches • Mutual Exclusion-software support • Semaphores • Monitors • Message Passing • Readers/Writers problem • Deadlock and starvation • Principles of deadlock • Deadlock prevention • Deadlock avoidance • Deadlock detection • An integrated Deadlock Strategy • Dining Philosophers Problem

  3. Introduction • Multiprogramming:- management of multiple processes within a set of processor system • Multiprocessing : Management of multiple processes within a multiprocessor • Distributed Processing: Management of multiple processes executing on multiple distributed computer system

  4. Key terms related to concurrency

  5. Concurrency • What is it? • Communication among processes • Sharing of and competing for resources • Synchronization of activities of multiple processes • Allocation of processor time to processes

  6. When concurrency arises • Multiple applications: • Structured applications • Operating system structure

  7. Race Conditions A Race Condition occurs, if two or more processes/threads access and manipulate the same data concurrently, and the outcome of the execution depends on the particular order in which the access takes place. Synchronization is needed to prevent race conditions from happening

  8. Principles of concurrency • Problems encountered during concurrency • Sharing of global resources is fraught with peril • Difficulty in managing the allocation of resources optimally • Difficulty in locating a programming error because results are typically not deterministic and reproducible

  9. Simple example Echo program is loaded in global memory and shared by applications Problem can be solved by controlled access to shared resource

  10. OS Concerns • What design and management issues are raised by concurrency? • OS should keep track of active processes • OS should allocate and deallocate resources to active processes • Processor time/memory/files/I-O devices • OS should protect against the interference by other processes • Result of a process should be independent of the speed of execution relative to other concurrent process (Process interaction)

  11. Process interaction

  12. Competition among Processes for Resources • 3 control problems • Mutual exclusion:- eg. Printer • Mutual exclusion leads to two more additional problems • Deadlock • Starvation • Mutual exclusion can be achieved by locking a resource prior to its use.

  13. Mutual exclusion

  14. Cooperation among processes by sharing • Eg:- shared variables/files/database • Data items may be accessed in reading and writing mode and only the writing mode must be mutually exclusive • Requirement: data coherence

  15. Cooperation among processes by Communication • Communication provides a way to synchronize or coordinate the various activities • This is done by messaging. • So Mutual exclusion is not a control requirement for this sort of cooperation • Has deadlock and starvation problems

  16. Requirements of mutual exclusion(ME) • ME should be enforced • A process that halts in its noncritical section should not interfere with other processes • No deadlock and starvation • When no process is there in the CS, a process requiring CS should be granted permission • Process remains in CS only for finite time

  17. Ways to arrive at mutual exclusion • Software approaches • Leave the responsibility to the processes that wish to execute concurrently. • Disadv is high processing overhead and bugs • Hardware approaches • Special purpose machine instructions • Adv of reducing overhead • Some level of support within the OS or programming language • Semaphores • monitors

  18. First Attempt Buzy Waiting : waiting process repeatedly reads the value of turn(global memory location) until its allowed to enter its critical section Disadvantage:- Pace of execution is dictated by the slower of the two processes If one process fails the other process is permanently blocked.

  19. Second attempt If one process fails outside the critical section, other process is not blocked. But if it fails within the critical section or after setting the flag then it blocks the other process

  20. Third attempt Eliminates the problems in second attempt. This guarantees mutual exclusion but creates deadlock, because each process can insist on its right to enter its critical section.

  21. Livelock • The process keeps setting and resetting the flags alternatively and gets neither process could enter its critical section. • Alteration in the relative speed of the two processes will break this cycle and allow one to enter the critical section • This is called as livelock

  22. Peterson’s Solution • Two process solution • The two processes share two variables: • int turn; • Boolean flag[2] • The variable turn indicates whose turn it is to enter the critical section. • The flag array is used to indicate if a process is ready to enter the critical section. flag[i] = true implies that process Pi is ready!

  23. Algorithm for Process Pi

  24. Mutual exclusion-Hardware approach • Interrupt Disabling • Special machine instructions • Compare and swap • exchange

  25. Interrupt Disabling • In an uniprocessor system concurrent processes can have only interleaved execution • Process runs until its interrupted • To guarantee ME its enough to prevent a process from being interrupted Disadvantages Degree of interleaving is limited Does not work in a multiprocessor architecture

  26. Special machine instructions • Processor designers have proposed several machine instructions that carry out two actions automatically(Read-Write/Read-Test) through a single instruction fetch cycle • Two such instruction • Compare and swap • Exchange instruction

  27. Compare and swap Checks a memory location (*word) against a test value(testval). If memory location currval=testval, its replaced by newval Otherwise left unchanged

  28. Compare and swap Shared variable bolt is initialized to 0 The only process that can enter critical section is one that finds bolt equal to 0 All other processes would go to buzy waiting mode

  29. Exchange

  30. Exchange contd… Shared variable bolt is initialized to zero Each process has a local variable key that is initialized to 1 Process that find bolt =0 alone enters the critical section Excludes all other processes by setting bolt=1 Once on exiting it resend bold to 0

  31. Properties of machine-instruction approroach

  32. Disadvantage • Buzy waiting is employed • Starvation is possible • Deadlock is possible

More Related