Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming.threads > #2173

Weakness of lockfree loops ...

From aminer <aminer@toto.net>
Newsgroups comp.programming.threads, comp.programming
Subject Weakness of lockfree loops ...
Date 2014-04-14 20:12 -0700
Organization albasani.net
Message-ID <lihth0$2bl$1@news.albasani.net> (permalink)

Cross-posted to 2 groups.

Show all headers | View raw


Hello,

We have to be smart more than that...

And we have to be carefull when using CAS based loops when
designing a Threadpool with a single concurrent FIFO Queue..


To understand why let's look at the following pop() function:

===

function TFIFOQUEUE_MPMC.pop(var obj:tNodeQueue):boolean;

var lastHead : long;
begin
   repeat
   lastHead:=head;
   if tail<>head
    then
     begin
       obj:=getObject(lastHead);

           if CAS(head,lasthead,lasthead+1)
           then
            begin
             result:=true;
            exit;
            end
           else  asm pause end;

      end
    else
        begin
         result:=false;
         exit;
        end;
   until false;
end;

===


imagine that we have 4 threads under contention on a Quadcore processor
and the four threads are crossing at the same time the "lastHead:=head;"
so if the CAS has succeeded for one thread the other will fail and will 
they will incur one more cache-line transfers for the "head" variable, 
so this will make the threads that have rolled back the lockfree loop 
loose there time in other cache-lines transfers, so this is not good for 
the Threadpool cause the load has to be more balanced, so this can lower 
the overall performance of the Threadpool under contention.

So i don't advice you to use lockfree CAS loops on the pop() side
of the queue when using them with Threadpools that uses a single 
concurrent FIFO queue.


Hope you have understood this...



Thank you,
Amine Moulay Ramdane.


Back to comp.programming.threads | Previous | Next | Find similar | Unroll thread


Thread

Weakness of lockfree loops ... aminer <aminer@toto.net> - 2014-04-14 20:12 -0700

csiph-web