lkml.org 
[lkml]   [2003]   [Jun]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRE: [PATCH] udev enhancements to use kernel event queue
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/

\
 
 \ /
  Last update: 2005-03-22 13:36    [W:1.633 / U:0.164 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site