Information Technology Reference
In-Depth Information
if(iShoudBuy){
buyMilk();
}
}
In this function, waitThenDrink() should (if there is no milk) wait (using
a condition variable) until there is milk, drink the milk, and if the milk is
now gone, return a nonzero value to flag that the caller should buy milk.
BuyMilk() should buy milk and then broadcast to let the waiting threads
know that they can proceed.
Again, test your code with varying numbers of threads.
13. Before entering a priority critical section, a thread calls PriorityLock::enter(priority)
and when the thread exits such a critical section it calls PriorityLock::exit() .
If several threads are waiting to enter a priority critical section the one
with the numerically highest priority should be the next one allowed in.
Implement PriorityLock using monitors (locks and condition variables)
and following the multi-threaded programming standards defined for the
class.
(a) Define the state and synchronization variables and describe the pur-
pose of each.
(b) Implement PriorityLock::enter(intpriority)
(c) Implement PriorityLock::exit()
Search WWH ::




Custom Search