what happened when `mpscq_node_t* prev = XCHG(&self->head,n)`

41 views
Skip to first unread message

by byaiu

unread,
Nov 16, 2018, 2:15:10 PM11/16/18
to Scalable Synchronization Algorithms
Hi,
I'm reading <<Intrusive MPSC node-based queue>> and found the code in mpscq_push `mpscq_node_t* prev = XCHG(&self->head,n)` confusing.
1. does the head and n point to the right address before and after the XCHG?
2. where should prev point to?

Dmitry Vyukov

unread,
Nov 16, 2018, 2:22:33 PM11/16/18
to lock...@googlegroups.com
On Fri, Nov 16, 2018 at 11:15 AM by byaiu <boyce...@gmail.com> wrote:
>
> Hi,
> I'm reading <<Intrusive MPSC node-based queue>> and found the code in mpscq_push `mpscq_node_t* prev = XCHG(&self->head,n)` confusing.
> mpscq figure

Hi by,

I don't have permissions to view the link you posted.

I assume you mean this algorithm:
http://www.1024cores.net/home/lock-free-algorithms/queues/non-intrusive-mpsc-node-based-queue

> 1. does the head and n point to the right address before and after the XCHG?

I am not sure what you mean by "right".
n is pointer to new node that needs to be enqueued. It is function
argument and is not changed by XCHG.
To the best of my knowledge head points to a right address. If I knew
about a bug in the algo, I would fix it.

> 2. where should prev point to?

prev points to the node that was head of the queue before XCHG operation.

Do you have some concrete scenario that you think is broken, or you
are confused about? If yes, describe it.
Reply all
Reply to author
Forward
0 new messages