On Mon, Nov 9, 2015 at 7:15 PM, Bernard Harmel <b.har...@gmail.com> wrote:
> Hi,
>
> I saw your bounded mpmc queue
> (http://www.1024cores.net/home/lock-free-algorithms/queues/bounded-mpmc-queue)
> in the spdlog library (https://github.com/gabime/spdlog)
> This is a great piece of code and I was wondering if it was easy/possible to
> add a 'reset' function which will set both enqueue and dequeue index value
> to zero to flush the queue content asap without using any lock.
> By the way I would like also to keep track of the current number of element
> in the queue. I have started by using atomic increment of a variable on
> successfull queue op and atomic decrement on successfull  dequeue op. Is it
> the best way to do it or is it possible to compute it from the enqueue and
> dequeue index in a lock free manner ?


+lock-free group

Hi Bernard,

Size is simple: do a relaxed load of enqueue_pos_ and dequeue_pos_ and
subtract. Mind possible wrap around and reordering (dequeue pos can be
larger than enqueue pos).

Reset is doable. Option (1) call dequeue until it returns false.
Option (2) CAS dequeue_pos_ to enqueue_pos_, then walk over the range
of cells, for each cell: wait until it is fully produced and mark it
as consumed.

-- 

--- 
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/CAEeQi3uXJ13t4zM3tOZT2yVV0oQLNmeHK2uc0AYAkYWuPewF2g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to