Re: [lock-free] regarding mpmc bounded queue

2017-10-15 Thread Dmitry Vyukov
On Sun, Oct 15, 2017 at 11:40 AM, user1990 k  wrote:
> Dear All,
>
> I was trying to understand this.
> http://www.1024cores.net/home/lock-free-algorithms/queues/bounded-mpmc-queue
>
> 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   |
> 
> yet to increment seq
>|pos = 1
>|   seq = 0
>| dif = -1
>|enqueue fails eventhough the queue is not full

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).

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"Scalable Synchronization Algorithms" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to lock-free+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/lock-free/CAEeQi3tzFPQAOhH5ae8B_8d0BO0WGYF02ftjuQgwyYzse2%2BBkA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[lock-free] regarding mpmc bounded queue

2017-10-15 Thread user1990 k
Dear All,

I was trying to understand this.
http://www.1024cores.net/home/lock-free-algorithms/queues/bounded-mpmc-queue

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   |

yet to increment seq
   |pos = 1
   |   seq = 0
   | dif = -1
   |enqueue fails eventhough the queue is not full


Thank you

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"Scalable Synchronization Algorithms" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to lock-free+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/lock-free/CAMYbg%2B%2BuHB_2O7a_pg20pwcJ3hJtCP6HM7W-bFX3ux5pSnRXvQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.