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

Davide Libenzi
2003-06-13T15:33:11Z

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