Presentation is loading. Please wait.

Presentation is loading. Please wait.

Homework 6 Sarah Diesburg Operating Systems CS 3430.

Similar presentations


Presentation on theme: "Homework 6 Sarah Diesburg Operating Systems CS 3430."— Presentation transcript:

1 Homework 6 Sarah Diesburg Operating Systems CS 3430

2 Helicopter Problem A helicopter ride has five seats, and it always carries a full load. Use lock(s) and condition variable(s) to write a procedure PersonArrives(), which is called whenever a person (thread) arrives. Once the load is full, one person (thread) should call UpAndAway(), and five threads should return from PersonArrives().  There should be no undue waiting: the helicopter should depart as soon as it has a full load.

3 Helicopter Problem int queue = 0; condition okToGo = NULL; Lock lock = FREE; PersonArrives() { lock.Acquire(); ++queue; if (queue < 4) { okToGo.wait(&lock); } else { GoGoGo(); queue = 0; okToGo.Signal(&lock); } lock.Release(); }

4 Helicopter Problem int queue = 0; condition okToGo = NULL; Lock lock = FREE; PersonArrives() { lock.Acquire(); ++queue; if (queue < 5) { okToGo.wait(&lock); } else { UpAndAway();= 0; okToGo.Signal(&lock); } lock.Release(); }

5 Helicopter Problem int queue = 0; condition okToGo = NULL; Lock lock = FREE; PersonArrives() { lock.Acquire(); ++queue; if (queue < 5) { okToGo.wait(&lock); } else { UpAndAway(); okToGo.Signal(&lock); queue = 0; } lock.Release(); }

6 Proving Correctness Mutual exclusion  All shared variables are locked e.g., queue  Signal() and Wait() are invoked between lock.Acquire() and lock.Release()

7 Proving Correctness Liveness  Maximum of 4 threads in okToGo.wait()  Every 5 th thread wakes up exactly four threads already waiting in okToGo.wait()  Additional threads wait at lock.Acquire()  As long as we have 5n threads, every thread will make progress

8 Proving Correctness Fairness  As long as we have FIFO queues at lock.Acquire()  The queuing policy at okToGo.wait() does not matter, since all four waiting threads will be awakened  As long as we have 5n threads  Every thread will get its chance

9 Common Pitfalls int queue = 0; condition okToGo = NULL; Lock lock = FREE; PersonArrives() { lock.Acquire(); ++queue; if (queue < 5) { okToGo.wait(&lock); } else { UpAndAway(); okToGo.Signal(&lock); queue = 0; lock.Release(); } Wait() requires lock on return No lock.Release()

10 Common Pitfalls int queue = 0; condition okToGo = NULL; Lock lock = FREE; PersonArrives() { lock.Acquire(); ++queue; lock.Release(); if (queue < 5) { lock.Acquire(); okToGo.wait(&lock); lock.Release(); } else { lock.Acquire(); UpAndAway(); okToGo.Signal(&lock); queue = 0; lock.Release(); } Unprotected states Multiple threads may wait here

11 Kernel Modules A kernel module is driver code that is dynamically loaded into the driver when it is needed  Also can be unloaded The kernel is an executable file  Can contain built-in driver code, but makes the executable bigger

12 Module Commands insmod – insert a module into the running kernel rmmod – remove a module from the running kernel modprobe – inserts a module, along with all other modules it depends on  Only using insmod for our project


Download ppt "Homework 6 Sarah Diesburg Operating Systems CS 3430."

Similar presentations


Ads by Google