RE: [PATCH] udev enhancements to use kernel event queue

Davide Libenzi (davidel@xmailserver.org)
Fri, 13 Jun 2003 08:44:59 -0700 (PDT)


On Fri, 13 Jun 2003, David Schwartz wrote:

> You could also do (in pseudo-code):
>
> top:
> ret <- v->counter
> inc ret
> LOCK incl v->counter
> cmp v->counter, ret
> jz end
> LOCK decl v->counter
> jmp top:
> end:
> return ret
>
> This does not strictly guarantee in order return values, but that's
> meaningless without a lock anyway.

It is even worse since it can return same values. Suppose counter is 0 :

TASK0 TASK1

top:
ret <- v->counter ; ret = 0
inc ret ; ret -> 1
LOCK incl v->counter ; counter -> 1

top:
ret <- v->counter ; ret = 1
inc ret ; ret -> 2
LOCK incl v->counter ; counter -> 2
cmp v->counter, ret ; match !! got 2
jz end
...

cmp v->counter, ret ; ret == 1 , counter == 2 no-match
jz end
LOCK decl v->counter ; counter -> 1
jmp top

Then TASK0 starts again with no interruption and gets 2. You need
instrucions that does atomic mod/cmp to do this kind of tricks.

- Davide

-
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/