For example suppose we want to ensure that procedure1 in process 1 gets

For example suppose we want to ensure that procedure1

This preview shows page 48 - 50 out of 102 pages.

For example, suppose we want to ensure that procedure1() in process 1 gets executed before procedure2() in process 2. // Process 1 // Process 2 procedure1(); wait(mysignal); signal(mysignal); procedure2(); ... ... These operations are a special case of interprocess communication . A semaphore is a flag which can have a more general value than just true or false. A semaphore is an integer counting variable and is used to solve problems where there is competition between processes. The idea is that one part of a program tends to increment the semaphore while another part tends to decrement the semaphore. The value of the flag variable dictates whether a program will wait or continue, or whether something special will occur. There are many uses for semaphores and we shall not go into them here. A simple example is reading and writing via buffers, where we count how many items are in the buffer. When the buffer becomes full, the process which is filling it must be made to wait until space in the buffer is made available. 4.4.8 Monitors Some languages (like Modula) have special language class-environments for dealing with mutual exclusion. Such an environment is called a monitor. A monitor is a language-device which removes some of the pain from synchronization. Only one process can be `inside' a monitor at a time - users don't need to code this themselves, they only have to create a monitor. A procedure or function defined under the umbrella of a monitor can only access those shared memory locations declared within that monitor and vice-versa. Wait and signal operations can be defined to wait for specific condition variables. A process can thus wait until another process sends a signal or semaphore which changes the condition variable. 4.5 Deadlock Waiting and synchronization is not all sweetness and roses. Consider the European road rule which says: on minor roads one should always wait for traffic coming from the right. If four cars arrive simultaneously at a crossroads (see figure) then, according to the rule all of them must wait for each other and none of them can ever move. This situation is called deadlock . It is the stale-mate of the operating system world.
Image of page 48
Figure 4.5: Deadlock in the European suburbs. 4.5.1 Cause Deadlock occurs when a number of processes are waiting for an event which can only be caused by another of the waiting processes. These are the essential requirements for a deadlock: 1. Circular waiting. There must be a set of processes where is waiting for a resource or signal from , is waiting for ... and is waiting for . 2. Non-sharable resources. It is not possible to share the resources or signals which are being waited for. If the resource can be shared, there is no reason to wait. 3. No preemption. The processes can not be forced to give up the resources they are holding.
Image of page 49
Image of page 50

You've reached the end of your free preview.

Want to read all 102 pages?

  • One '20

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors