Hello,
Look at:
http://www.emadar.com/fpc/lockfree.htm In the pop side we have:
--------------
function gFLQueue.pop(var tm:_R):boolean;
var newhead, lastHead : integer;
begin
repeat lastHead:=head;
if tail<>head then begin
pointer(newHead):=interlockedCompareExchange(pointer(head),pointer(lastHead
+1),pointer(lasthead));
if newHead=lastHead
then
begin tm:=getObject(lastHead);
result:=true; exit;
end; end
else
begin result:=false; exit;
end; until false; end;
{$ENDIF} end.
----
If you have noticed, after he is incrementing head with in
interlockedCompareExchange(), he is doing a tm:=getObject(lastHead);
and this is an error i think, cause if the thread is preempted and another
thread have put another value in the same place as lashead, the value will
be invalid and corrupted.
I have corrected this problem in my lockfree_mpmc fifo queue version
1.1.
So, becarefull with those lockfree algorithms.
thank you.
Amine Moulay Ramdane.