Hello,
I have enhanced my Scalable sufficiently fair MPMC priority Queue...
I have added a repeat until so that if the consumer
is wacked up and it doesn't find any items in the queues
and the wait parameter is true so it will loop again.
Here is my algorithm in the pop() side:
===
function TPQueue.Pop(var context:tobject;var index:long;wait:boolean=true):boolean;
var
// Context: Tobject;
context1:TObject;
i:integer;
begin
if index = high(long)
then
begin
index:=LockedIncLong(balance3) mod Fthreadcount;
end;
repeat
if Queues[index].count = 0
then zqueue.push(tobject(index));
if wait=true then events[index].wait;
result:=Queues[index].pop(context);
if result
then
begin
while zqueue.pop(tobject(context1))
do
begin
if not ((Queues[index].count = 0)
and (integer(context1) = index))
then events[integer(context1)].signal;
end;
end
else
begin
for i:=Fthreadcount-1 downto 0
do
begin
result:=Queues
.pop(context);
if result then break;
end;
end;
until ((wait=true) and (result=false));
end;
==
You can download again my Scalable sufficiently fair MPMC priority Queue
from:
http://pages.videotron.com/aminer/
Thank you,
Amine Moulay Ramdane.