#i nclude #include “
Автор admin
Суббота, 27 июня 2009 11:32
#i nclude #include “zthread/Thread.h” #include “zthread/Mutex.h” #include “zthread/Guard.h” #include “zthread/Condition.h” #include “zthread/ThreadedExecutor.h” using namespace ZThread: using namespace std: class Car { Mutex lock; Condition condition: bool waxOn; public: CarO : condition(lock). waxOn(false) {} void waxedO { Guard g(lock); waxOn = true: // Готовность к полировке condition, signal О: } void buffedO { Guard g(lock); waxOn = false: // Готовность к нанесению следующего слоя condition.signal О; } void waitForWaxingO { Guard g(lock); while(waxOn == false) condition.waitO; } void waitForBuffingO { Guard g(lock): while(waxOn == true) condition.waitO; } }: class WaxOn : public Runnable { CountedPtr car; public: WaxOn(CountedPtr& c) : car(c) {} void run() { try { while(!Thread::interruptedO) { cout « “Wax On!” « endl: Thread::sleep(200): 572 Глава 11 • Многопоточное программирование car->waxed(); car->waitForBuffing(); } } catch(Interrupted_Exception&) { /* Exit */ } cout « “Ending Wax On process” « endl; } }: class WaxOff : public Runnable { Counte
Комментарии закрыты.
Последние комментарии