[parisc-linux] semaphore problem

Matthew Wilcox matthew@wil.cx
Sat, 17 Mar 2001 02:34:31 +0000


On Fri, Mar 16, 2001 at 06:25:49AM +0000, Matthew Wilcox wrote:
> 
> as i suspected, the pipe problem was a semaphore problem.  here's how
> it works:

OK, I've redesigned the semaphore code on the whiteboard.  Here's how it
works.

The `count' variable is initialised to N for N simultaneous accesses.
A value of 0 indicates there are no processes waiting.  A value of -1
indicates there are processes waiting.  Each up() increments the count by
1 if non-negative.  if negative, it _decrements the count.  So we can
distinguish between the following cases:

 N : N more processes allowed in
 0 : no new processes allowed in, none waiting
-1 : processes waiting, no wakeups in flight
-N : N - 1 wakeups in flight

This allows us to implement wakeup stealing if we want.  Unsure about
starvation issues in that case.  Think about two processes; process A
down down() up() down() up() very frequently.  process B does a down().
do we want to switch to B the next time A does an up()?  or do we want
A to steal B's wakeup?

i shan't implement it now, but it's something to consider.

-- 
Revolutions do not require corporate support.