Community
cancel
Showing results for 
Search instead for 
Did you mean: 
aminer10
Beginner
34 Views

About lockfreE_mpmc .....



Hello,

I wrote:
 
> Hello all,
>
> I think i have discovered a problem with lockfree_mpmc:
>
> You will find the source code of lockfree_mpmc at:
>
> http://pages.videotron.com/aminer/
>
>
> So please follow with me:
>
> If you take a look at the lockfree_mpmc , here is  the source code
> of the push() method:
>
> ---
>
> function TLockfree_MPMC.push(tm : tNodeQueue):boolean;
> var lasttail,newtemp:long;
> i,j:integer;
> begin
>
> if getlength >= fsize
>  then
>      begin
>          result:=false;
>          exit;
>      end;
> result:=true;
>
> newTemp:=LockedIncLong(temp);
>
> [1] lastTail:=newTemp-1;
> [2] setObject(lastTail,tm);
>
> repeat
>
> if CAS(tail,lasttail,newtemp)
>   then
>      begin
>       exit;
>      end;
> sleep(0);
> until false;
>
> end;
>
> ---
>
> As you know in the x86 architecture Loads may be reordered with older stores
> to different locations.
>
> So in line [2] there is a load of tail and lasttail to the registers of the
> processor
> before calling setobject() and just before on line [1] there is a store to
> lasttail.
>
> So as you have noticed the processor can then reorder the loads on line [2]
> with the older
> store on line [1] and this will cause a problem, so i think i have to insert
> an mfence between
> line [1] and line [2].


In the intel's processor manual: link in section 8.2.3.4 it is stated that loads may not be
reordered with earlier stores to the same location, so lockfree_mpmc doesn't need
and mfence between line [1] and [2] cause there is a store and after that a load to
the same location that is lastTail:.
 
 
You can download lockfree_mpmc from:
 
 
 
 
Sincerely,
Amine Moulay Ramdane.
 
 
 
 
0 Kudos
0 Replies
Reply