![]() Thread B can also invoke wait() and be placed in the wait set along with thread A. If thread B exits the monitor section without calling notify() on the condition variable, then thread A will remain waiting in the wait set. Since no other thread owns the monitor, thread B successfully acquires the monitor and continues execution. ![]() Say another thread B comes along and gets placed in the entry set, while thread A sits in the wait set. New threads requesting ownership of the monitor get placed into the entry set. While thread A owns the monitor no other thread will be able to execute any of the critical sections protected by the monitor. Thread A will continue to execute within the monitor section till it exits the monitor or calls wait() on an associated condition variable and be placed into the wait set. If no other thread owns the monitor, which is equivalent of saying no thread is actively executing within the monitor section, then thread A will acquire the monitor and is said to own it too. When a thread A enters a monitor it is placed into the entry set. One is the entry set and the other is the wait set. Theoretically, Another way to think about a monitor is to consider it as an entity having two queues or sets where threads can be placed. Monitors allow threads to exercise mutual exclusion as well as cooperation by allowing them to wait and signal on conditions. ![]() You can think of a monitor as a mutex with a wait set. In Java each object is a monitor and implicitly has a lock and is a condition variable too. Monitor is made up of a mutex and one or more condition variables. ![]()
0 Comments
Leave a Reply. |