Thursday, May 3, 2007

Semaphores

Implemented semaphores. Each semaphore holds a list of tasks that are waiting on it. You can create one with an initial value N. N is the number of tasks that can concurrently access it. It gets decremented every time a task calls a semaphore. If N is already 0 when a task requests a lock on it, the task has to be suspended. Tested with two tasks. Need to test that more.

Implementing threads should be easy. Something about last words comes to mind :)! In switching a task, you have to switch a whole task out and put the new one in. For threads, you don't have to swap out the context of a task, just the PC and a much faster timer for each thread in the process. So the process TCB struct has to change to accomodate threads.

Finally getting a feel for what a scheduler should look like! It is a state machine duh! Now as far as implementing state machines go, I have no idea :).

No comments: