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
Jan 15, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment