Variable is signaled and there is at least one thread

This preview shows page 4 - 6 out of 6 pages.

variable is signaled and there is at least one thread on waiting on the condition variable, the signaling thread hands occupancy over to the signaled thread , so that no other thread can gain occupancy in between. 2. Non-blocking condition variables (signal and continue) With non-blocking condition variables ( signal and continue condition variables), signaling does not cause the signaling thread to lose occupancy of the monitor. Instead the signaled threads are moved to the e queue. There is no need for the s queue. Figure 2: Non-blocking condition variables (signal and continue) implementation With non-blocking condition variables, the signal operation is often called notify. It is also common to provide a notifyAll operation that moves all threads waiting on a condition variable to the e queue. Each monitor operation in this implementation technique (signal and continue) is explained below. enter the monitor operation: enter the method if the monitor is locked add this thread to e block this thread else lock the monitor leave the monitor operation: return from the method schedule
Image of page 4

Subscribe to view the full document.

5 wait c operation: add this thread to c .q block this thread schedule notify c operation : if there is a thread waiting on c .q select and remove one thread t from c .q (t is called "the notified thread") move t to e notify all c operation: move all threads waiting on c .q to e schedule operation : if there is a thread on e select and remove one thread from e and restart it else unlock the monitor As a variation on this scheme, the notified thread may be moved to a queue called w, which has priority over e. 3. Java Monitor Implementation Technique Figure 3: Java monitor implementation In the Java language, each object may be used as a monitor. (However, methods that require mutual exclusion must be explicitly marked as synchronized.) Rather than having explicit condition variables,
Image of page 5
6 each monitor (i.e. object) is equipped with a single wait queue, in addition to its entrance queue. All waiting is done on this single wait queue and all notify and notify all operations apply to this queue. This approach has also been adopted in other languages such as C#. In some case notify signaling may be done implicitly (i.e., returning thread will trigger implicit signaling).
Image of page 6
You've reached the end of this preview.
  • Spring '12
  • GwangS.Jung
  • monitor

{[ snackBarMessage ]}

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