5. Predavanje - VTS NS
5. Predavanje - VTS NS
5. Predavanje - VTS NS
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
MonitoriKako rešiti slučaj izlaska iz sredine operacije (sa return ili uslučaju izuzetka)?int Monitor::criticalSection () {sem.wait();return f()+2/x; // gde pozvati signal()?}Rešenje:class Mutex {public:Mutex (Semaphore* s) : sem(s){ if (sem) sem->wait(); }~Mutex () { if (sem) sem->signal(); }private:Semaphore *sem;};void Monitor::criticalSection () {Mutex dummy(&sem);//... telo kritične sekcije}16/285