Boost logo

Boost Users :

Subject: Re: [Boost-users] Help with lockfree queue
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2013-11-12 23:40:18


On 13/11/2013 12:58, Quoth TYSON Kieran:
> The program compiles and runs without fault up until the program exits
> and the queues destructor is called. An unhandled exception is thrown on
> the destruction of the queue.

Queue destruction is not threadsafe; you need to be able to guarantee
that no thread is currently in the process of trying to push or pop at
the time that the destructor is called.

Have you traced what exception is actually thrown? And also, what
version of Boost and what platform are you running on?

> Are there size limitations on the message of a lockfree queue?

IIRC, if you use fixed_size you're limited to a max of 65535 objects,
but I don't think there's a per-object size limit; it just needs to be a
POD-like type (trivially constructable, copyable, and destructible).

But bear in mind that the nature of lock-free access (particularly for
an MPMC algorithm) means that the data might be copied more than once
for a single push/pop operation, so given the size of your payload you
might be better off keeping pointers in your queue rather than the full
object anyway. (You can create the full objects up front and then push
the pointers on a lock-free stack as a freelist; to add an item you pop
one off the freelist, fill it, and push it into the queue; once it's
popped off the queue and processed you can push the pointer back onto
the freelist stack.)

Unfortunately given the type restrictions you can only store a bare
pointer, not a smart pointer. So if you take this approach you'll have
to remember to explicitly pop and delete any objects remaining in the
queue or freelist when you're done.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net