正在加载图片...
5.4.1 Concept of Monitors(9/10) Implementation of Condition Class Condition I int numWaiting =0 WaitQueue q Condition: Wait(lock)t Condition Signalo t numWaiting++ if((numWaiting >0) Add this thread t to g Remove a thread t from q release(lock) wakeup(t); / need mutex schedule(; /need mutex numWaiting-- require(lock)5.4.1 Concept of Monitors(9/10) • Implementation of Condition 14 Class Condition { int numWaiting = 0; WaitQueue q; } Condition::Wait(lock) { numWaiting++; Add this thread t to q; release(lock); schedule(); // need mutex require(lock); } Condition::Signal() { if ((numWaiting > 0) { Remove a thread t from q; wakeup(t); //need mutex numWaiting--; } }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有