Thanks Nitsan and Dmitry for the clear explanation of #2
I understand it now.
However, In the case of concurrent queues,
I'm not sure if we should interpret the offer() semantics of java in such a
strict way. (returns false iff queue is full)
Because in a concurrent situation, the very question "is the queue full?"
loses meaning
Even when we return false from offer(), by the time we detect the false
return, other consumers can race and make the queue not full.
There is no way to enforce a strict offer() behaviour. Maybe relaxed{Offer,
Poll} methods should be the default {Offer, Poll} method
On Friday, May 26, 2017 at 2:35:56 PM UTC+5:30, Dmitry Vyukov wrote:
>
> On Fri, May 26, 2017 at 10:50 AM, Sharath Gururaj <[email protected]
> <javascript:>> wrote:
> > This question is regarding JCTools MPMC queue which is a java port of
> Dmitry
> > Vyukov's Mpmc C++ implementation
> >
> >
> https://github.com/JCTools/JCTools/blob/011e1c3a6919a0fb641815c7429e0742911b9a79/jctools-core/src/main/java/org/jctools/queues/MpmcArrayQueue.java#L141
>
> >
> > Everything inside the if condition of line 140 seems to be redundant.
> Here
> > are my questions: seems
> >
> > 1. the check
> > pIndex - capacity >= (cIndex = lvConsumerIndex())
> > seems wrong to me. The >= actually be <=
> >
> > 2. The inner else seems to be redundant. Under what conditions can it be
> > that seq < pIndex but array has free capacity?? If so then we can remove
> the
> > inner if..else and simply return false
>
> Hi Sharath,
>
> It depends on what semantics you want to get from the queue.
> This check seems to lead to active spinning if we see there is a
> pending consumer that started dequeue but did not finish (executed
> CAS, but not updated seq).
> Also, I think it makes the queue linealizable, per se it is not which
> can be confusing in some cases.
>
> Re 2: when a consumer has started an operation but did not finish it.
> Moreover, an arbitrary number of other consumers might have drained
> the queue completely, but producer is still stuck due to the first
> pending consumer.
>
> Re 1: that I don't know as I don't see code for lvConsumerIndex,
> calcSequenceOffset and some other functions.
>
--
---
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/lock-free/a8a5b024-5832-4aff-bbf0-0a63f2212007%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.