regarding mpmc bounded queue

83 views
Skip to first unread message

user1990 k

unread,
Oct 15, 2017, 5:41:28 AM10/15/17
to lock...@googlegroups.com
Dear All, 

I was trying to understand this. 

Let me consider enqueue scenario [ both threads ] 

Thread 1 in core 0      | Thread 2 in core 0

pos = 0    | 
seq = 0    |    
dif = 0    |    
cas succeed, pos =1   |
<delay/preempted>
yet to increment seq   
                                   |    pos = 1
   |   seq = 0
   | dif = -1
   |    enqueue fails eventhough the queue is not full 


Thank you

Dmitry Vyukov

unread,
Oct 15, 2017, 5:43:45 AM10/15/17
to lock...@googlegroups.com
Hi,

The seq are initialized to their indexes initially, see ctor:

for (size_t i = 0; i != buffer_size; i += 1)
buffer_[i].sequence_.store(i, std::memory_order_relaxed);

So for pos=1 seq will be 1 (diff=0).
Reply all
Reply to author
Forward
0 new messages