[fpc-devel] LockFree Queue algorithm

DarekM darekm at emadar.com
Sun Jan 27 15:39:37 CET 2008


Martin Friebe pisze:
> What about a long running (eg daemon) application?
>
> If temp/tail hits the upper boundary of Integer?
>
> (If I understand it correctly)
> I don't know if interlockedIncrement gives a boundary error, but if not,
> it still fails.
> - With currently integer, it gets a negative value, once crossing
> 0x7fffffff, and SetObject will attempt to read/write out-of-bounds 
> memory.
> - Assuming temp/tail being unsigned: it will go from 0xffffffff to 0.
> "0xffffffff mod fsize" may return a value greater 0, "0x00 mod fsize"
> will be zero. You make an unexpected jump within the list.
>


Thats right.
But I can avoid this.
1. make length of tab equal power of two
2. use longword instead of integer
3.instead MOD use   result:=tab[lp and  fmask];
 and fmask:=$F or $FF or $FFF


Thanks to find bug.


Darek







More information about the fpc-devel mailing list