| Scheduling Algorithms | |||||
|---|---|---|---|---|---|
| Job | length | arrival time | FIFO | RR | SRTF |
| 0 | 75 | 0 | 75 | 205 | 205 |
| 1 | 40 | 10 | 115 | 125 | 75 |
| 2 | 25 | 10 | 140 | 105 | 35 |
| 3 | 20 | 80 | 160 | 135 | 100 |
| 4 | 45 | 85 | 205 | 200 | 145 |
| Avg. RT | 102 | 119 | 75 | ||
| Job | length | Completion Time | |
|---|---|---|---|
| RR | MLFB | ||
| 1 | 10 | 28 | 28 |
| 2 | 30 | 65 | 65 |
| 3 | 25 | 60 | 60 |
| Avg. RT | 51 (?*) | 51 (?*) | |
| Queue | Time Slice | Job |
|---|---|---|
| 1 | 1 | 111, 212, 313, 124, 137, 1410, 1513, 1616, 1719, 1822, 1925, 11028 |
| 2 | 2 | 236, 339, 2512, 3515, 2718, 3721, 2924, 3927, 21130, 31132, 21334, 31336, 21538, 31540, 21742, 31744, 21946, 31948, 22150, 32152, 22354, 32356, 22558, 32560, 22762, 22964, 23065 |
class TurnstileController
{
public:
void Enter();
void Exit();
int PrintCurrentOccupants();
private:
// The number of occupants in the room
int occupants;
// A counting semaphore used to track the remaining
// capacity of the room
Semaphore capacityRemaining;
// A mutex that only allows one person to enter the room
// at a time
Semaphore entranceMutex;
// A mutex that only allows one person to exit the room
// at a time
Semaphore exitMutex;
}
TurnstileController::TurnstileController()
{
occupants = 0;
capacityRemaing->value = MAX_CAPACITY;
entranceMutex->value = 1;
exitMutex->value = 1;
}
TurnstileController::Enter()
{
entranceMutex->Wait();
capacityRemaining->Wait();
occupants = occupants + 1;
entranceMutex->Signal();
}
TurnstileController::Exit()
{
exitMutex->Wait();
occupants = occupants - 1;
capacityRemaining->Signal();
exitMutex->Signal();
}
Test&set works on both uniprocessors and multiprocessors. However, even if implemented carefully, test&set will result in some busy waiting.
Disabling interrupts will only work on uniprocessors. Worse, the timing of the re-enabling of interrupts is tricky (e.g. in NACHOS, it is the responsibility of the next running thread to re-enable interrupts upon executing).
Because a modern OS is generally required to run on a multiprocessor architecture, the only real choice is test&set. Hopefully the overhead of some busy-waiting will be an acceptable tradeoff for the increased throughput of multiple CPUs.