Re: [PATCH] Lightweight userspace semphores...

Martin Wirth (Martin.Wirth@dlr.de)
Wed, 27 Feb 2002 18:17:41 +0100


Hubertus Franke wrote:

> Again, the trick is to not
> sync the state of the kernel and the user level. It comes naturally
> if you properly separate the duties.
>

Your code for usema_down is simply:

int usema_down(ulock_t *ulock)
{
if (!__ulock_down(ulock)) {
return 0;
}
return ulock_wait(ulock,0);
}

This means you do not recheck if the usema is really available after you
return form ulock_wait(), but you may have the following situtation:

Process 1 Process 2 Process 3
down

down
-> call usema_wait
but gets preempted shortly
before it
can enter kernel mode

up
(kernel sema is free)

down -> got it

resume execution,
thinks its also got it
because kernel sema is free!

Now you have two owners!!

Martin Wirth

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/