Search the web
Sign In
New User? Sign Up
liblf-dev · Lockfree data structure implementers
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Real people. Real stories. See how Yahoo! Groups impacts members worldwide.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
an implementation of lock-free queue without atomic   Message List  
Reply | Forward Message #294 of 300 |
Re: an implementation of lock-free queue without atomic


--- In liblf-dev@yahoogroups.com, Chris Purcell <chris.purcell.39@...>
wrote:
>
> There don't appear to be any memory barriers in your code. How are you
> avoiding the issue of out-of-order execution on multiprocessor machines?
>
> Chris

Thank you , Chris . Sorry for my poor english , I will try my best to
express my own opinion .
It is true that I don't use any memory barriers in my code and this queue
can only be used in single reader and single writer . First of all , we could
assume that the assignment is atomic on uniprocessor machine , Such as
int ret = 11 ;
in asm compiled by gcc 3.4.3 , it is
c7 45 fc 0b 00 00 00 movl $0xb,0xfffffffc(%ebp)

There are two key ways I used in the implementation :
1. Combination of queue with ring array ;
2.There is almost no same memory which the enqueue thread and the dequeue
thread need to access .
Look at the struct of queue_t :
#define MAX_RING_SIZE 3
typedef struct _queue_st queue_t ;
struct _queue_st{
qnode_t *nodes[MAX_RING_SIZE] ;

int enqueue ;
int dequeue ;

qnode_t *enlast ;
} ;

The enqueue function only use member enqueue/enlast/nodes , and the dequeue
function only use member dequeue and nodes . Nodes is a small ring array , when
enqueue function will put a node , it will find a NULL element of nodes ,
otherwise , it put this node into old link , pointed by member enlast ; if the
dequeue function want to get a node , it will get a node from a old link ,
indexed by member dequeue utill the link is NULL .
The enqueue function and dequeue function can not access the same memory
at the same time , only if queue_t's member enqueue is equal to dequeue . I
assume that the assignment is atomic on uniproccessor as before , so only after
queue->nodes[queue->dequeue] = NULL is successful , then enqueue function can
put its node to this link . On the other hand , only after queue->nodes[old] =
node is successful , then dequeue fucntion can get the node .
Even on multiproccessor machines , if movl instruction is atomic ,
the dequeue function only get the NULL value after odes[old] = node is
successful .
Best Regards .




Mon Mar 30, 2009 3:37 am

romandion78
Offline Offline
Send Email Send Email

Forward
Message #294 of 300 |
Expand Messages Author Sort by Date

I have an idea about lock-free queue without atomic , you can find source code at http://code.google.com/p/liblfqueue/downloads/list . Any body can send email...
romandion78
Offline Send Email
Mar 26, 2009
8:59 am

There don't appear to be any memory barriers in your code. How are you avoiding the issue of out-of-order execution on multiprocessor machines? Chris...
Chris Purcell
c_purcell_39
Offline Send Email
Mar 26, 2009
11:13 am

... Thank you , Chris . Sorry for my poor english , I will try my best to express my own opinion . It is true that I don't use any memory barriers in my...
romandion78
Offline Send Email
Mar 31, 2009
7:29 am

I'm very sorry that I can not find my posted reply in this groups , this is third time .why ? ... Thank you , Chris . Sorry for my poor english , I will try...
Roman Dion
romandion78
Offline Send Email
Mar 31, 2009
7:29 am

The issue that concerns me is the ordering of memory operations on the node pointer and on the node itself. For instance, the write of the node's address to...
Chris Purcell
c_purcell_39
Offline Send Email
Mar 31, 2009
6:05 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help