Homework 6 Sarah Diesburg Operating Systems CS 3430
Homework 6 Sarah Diesburg Operating Systems CS 3430
Helicopter Problem n n n A helicopter ride has five seats, and it always carries a full load. Use lock(s) and condition variable(s) to write a procedure Person. Arrives(), which is called whenever a person (thread) arrives. Once the load is full, one person (thread) should call Up. And. Away(), and five threads should return from Person. Arrives(). q There should be no undue waiting: the helicopter should depart as soon as it has a full load.
Helicopter Problem int queue = 0; condition ok. To. Go = NULL; Lock lock = FREE; Person. Arrives() { lock. Acquire(); ++queue; if (queue < 4) { ok. To. Go. wait(&lock); } else { Go. Go(); queue = 0; ok. To. Go. Signal(&lock); } lock. Release(); }
Helicopter Problem int queue = 0; condition ok. To. Go = NULL; Lock lock = FREE; Person. Arrives() { lock. Acquire(); ++queue; if (queue < 5) { ok. To. Go. wait(&lock); } else { Up. And. Away(); = 0; ok. To. Go. Signal(&lock); } lock. Release(); }
Helicopter Problem int queue = 0; condition ok. To. Go = NULL; Lock lock = FREE; Person. Arrives() { lock. Acquire(); ++queue; if (queue < 5) { ok. To. Go. wait(&lock); } else { Up. And. Away(); ok. To. Go. Signal(&lock); queue = 0; } lock. Release(); }
Proving Correctness n Mutual exclusion q All shared variables are locked n q e. g. , queue Signal() and Wait() are invoked between lock. Acquire() and lock. Release()
Proving Correctness n Liveness q q Maximum of 4 threads in ok. To. Go. wait() Every 5 th thread wakes up exactly four threads already waiting in ok. To. Go. wait() Additional threads wait at lock. Acquire() As long as we have 5 n threads, every thread will make progress
Proving Correctness n Fairness q q As long as we have FIFO queues at lock. Acquire() The queuing policy at ok. To. Go. wait() does not matter, since all four waiting threads will be awakened As long as we have 5 n threads Every thread will get its chance
Common Pitfalls int queue = 0; condition ok. To. Go = NULL; Lock lock = FREE; Person. Arrives() { lock. Acquire(); ++queue; if (queue < 5) { ok. To. Go. wait(&lock); } else { Up. And. Away(); ok. To. Go. Signal(&lock); queue = 0; lock. Release(); } } Wait() requires lock on return No lock. Release()
Common Pitfalls int queue = 0; condition ok. To. Go = NULL; Lock lock = FREE; Person. Arrives() { lock. Acquire(); ++queue; lock. Release(); if (queue < 5) { lock. Acquire(); ok. To. Go. wait(&lock); lock. Release(); } else { lock. Acquire(); Up. And. Away(); ok. To. Go. Signal(&lock); queue = 0; lock. Release(); } } Unprotected states Multiple threads may wait here
Kernel Modules n A kernel module is driver code that is dynamically loaded into the driver when it is needed q n Also can be unloaded The kernel is an executable file q Can contain built-in driver code, but makes the executable bigger
Module Commands n n n 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 q Only using insmod for our project
- Slides: 12