dave-hillier / disruptor-unity3d

Basic implementation of Disruptor for Unity3d
Apache License 2.0
200 stars 35 forks source link

Could you explain this to me? #8

Closed sebas77 closed 5 years ago

sebas77 commented 5 years ago

https://github.com/dave-hillier/disruptor-unity3d/blob/717491f41d8663949b2d05056bb42bde17f61ce3/DisruptorUnity3d/Assets/RingBuffer.cs#L89

I am trying to understand what you wanted to achieve with this while here. I suspect you were waiting for a dequeue, but this would enter in an infinite loop in a single threaded scenario. I don't know where the data structure is going to be used, so I need it to work under any scenario. I can reproduce the deadlock.

sebas77 commented 5 years ago

OK it seems that the deadlock was due to a bug of mine, but I would like to understand the logic anyway if you have the time.

Edit: I got the gist of it now, but I still wonder how can I make enter in a deadlock without even using multiple threads. Somehow is due to the code crashing somewhere tho.

dave-hillier commented 5 years ago

The queue is designed to block when you reach full capacity. A typical scenario is a producer-consumer inter-thread communication. Once the queue becomes full, I thought it was sensible behaviour to stop that thread.

For more information about disruptor see here: https://lmax-exchange.github.io/disruptor/

sebas77 commented 5 years ago

Ok that's what I couldn't understand. It's a circular buffer isn't it? How can it get to the full capacity therefore? Shouldn't it just loop around? @dave-hillier

On Mon, 11 Mar 2019, 08:25 Dave Hillier, notifications@github.com wrote:

The queue is designed to block when you reach full capacity.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/dave-hillier/disruptor-unity3d/issues/8#issuecomment-471445882, or mute the thread https://github.com/notifications/unsubscribe-auth/AA5s49SL93iGYpqEN1zCZVAkYoHEbf20ks5vVhMHgaJpZM4bncp4 .

sebas77 commented 5 years ago

ah thank you for the disruptor link! I guess you are suggesting me to updated to the latest version then, although I notice that in that implementation the ringbuffer is actually a publisher/consumer and not just a circular buffer. I actually created my publisher/consumer on top of your implementation.

dave-hillier commented 5 years ago

I am not sure what your question is or the problem you have.

It is designed to be a replacement to a replacement for something like concurrent queue. The fact it is a ring buffer is an implementation detail.

From Readme

I wanted to replace the ConcurrentQueue with something that did not have any extra allocation overhead. A circular buffer is a fixed size data structure that could be used in this case. When searching for an existing implementation I remembered the Disruptor; a high performance lockless queue. Disruptor has many good qualities, but in my case, I only care about the lack of allocations.