Recent

Author Topic: A Scalable MPMC FIFO priority Queue  (Read 8124 times)

aminer

  • Hero Member
  • *****
  • Posts: 956
Re: A Scalable MPMC FIFO priority Queue
« Reply #15 on: June 27, 2013, 11:28:19 pm »

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.



aminer

  • Hero Member
  • *****
  • Posts: 956
Re: A Scalable MPMC FIFO priority Queue
« Reply #16 on: June 28, 2013, 05:16:24 pm »

Hello,


I have changed the name of my queue, i will call it a
scalable and relaxed MPMC priority Queue.

Description:

A scalable and relaxed MPMC priority Queue.

Relaxed means not a strict FIFO, but even if  it's not a strict FIFO
it processes the jobs in a FIFO order in each queue, that's also interresting.

The following have been added:

- You can give the following priorities to jobs:

LOW_PRIORITY
NORMAL_PRIORITY
HIGH_PRIORITY

- A queue for each worker thread and it uses work-stealing - for more efficiency -

- Enters in a wait state when there no is job in the queue - for more efficiency -

- Uses O(1) complexity on enqueue and O(3) complexity worst case on dequeue.


You can download it from:


http://pages.videotron.com/aminer/



Thank you,
Amine Moulay Ramdane.



 

TinyPortal © 2005-2018