[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: "Real" Multitasking (Re: GNO questions...)
In article <jmk3.735453502@crux1.cit.cornell.edu> jmk3@crux3.cit.cornell.edu (Jay Krell) writes:
>
>What's a semaphore? (Maybe I should read comp.unix.*)
>
A semaphore is a pretty simple data structure that can be used to solve
synchronization probles, such as multiple processes accessing a global
variable.
A semaphore can be initialized as follows:
Semaphore s = InitialValue;
Each semaphore, then, supports two atomic (that is, they can't be interrupted
by the scheduler) operations, P and V. They have the following effects:
P(s)
{
while (s <= 0)
;
s--;
}
V(s)
{
s++
}
Note that in an actual implementation, a process doesn't busy wait in the
while loop inside P; instead, the process would be blocked once it
became apparent that it was going to be stuck.
--
Jim Wong (jimwong@owlnet.rice.edu)