Jan 15, 2009

Semaphore implementation

Semaphore implementation
typedef struct
{
int value;
struct process* list;
} semaphore;

wait(semaphore S)
{
s.value—
if(s.value<0)
{
put the process p in S.list
block;//busy waiting, in the waiting list, not consume the cpu time
}
}

signal(semaphore S)
{
s.value++;
if(s.value<=0)
{
remove the process p from s.l;
wakeup(p);//in the ready list
}
}
The wait signal and wait process should be atomic, so in the one processor condition, we disable the interrupt during signal and wait

No comments:

Post a Comment