Re: [Boost-users] [LockFree] a queue of std::shared_ptr?

Hello All, If we can't use shared_ptr in a lockfree queue, how can I share data between different queue ? I have some data that I have to be put in different queues and I want to avoid that I have to copy this data for each queue. -- View this message in context: http://boost.2283326.n4.nabble.com/LockFree-a-queue-of-std-shared-ptr-tp4642... Sent from the Boost - Users mailing list archive at Nabble.com.

On Thu, Feb 14, 2013 at 10:17 AM, chris
Hello All,
If we can't use shared_ptr in a lockfree queue, how can I share data between different queue ?
I have some data that I have to be put in different queues and I want to avoid that I have to copy this data for each queue.
1) Use raw pointers with boost lockfree queues 2) Use shared pointers with a std::queue and a boost::mutex to ensure thread safety (note that this may not necessarily be slower than using the lockfree queue) 3) Use moveable objects with boost container deque There are more options, if one of these does not suffice. Brian

If I define a structure that contains a shared_ptr. Can I put this
structure in a lockfree queue ?
On Thu, Feb 14, 2013 at 9:21 PM, Brian Budge
On Thu, Feb 14, 2013 at 10:17 AM, chris
wrote: Hello All,
If we can't use shared_ptr in a lockfree queue, how can I share data between different queue ?
I have some data that I have to be put in different queues and I want to avoid that I have to copy this data for each queue.
1) Use raw pointers with boost lockfree queues 2) Use shared pointers with a std::queue and a boost::mutex to ensure thread safety (note that this may not necessarily be slower than using the lockfree queue) 3) Use moveable objects with boost container deque
There are more options, if one of these does not suffice.
Brian _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

On Feb 14, 2013 11:55 PM, "Chris Herssens"
If I define a structure that contains a shared_ptr. Can I put this
structure in a lockfree queue ?
No. Any struct with nontrivial member is also nontrivial. Here when I say nontrivial, I mean that it cannot simply be bitwise copied. Brian Brian

Hi Chris, Am 14.02.2013 19:17, schrieb chris:
Hello All,
If we can't use shared_ptr in a lockfree queue, how can I share data between different queue ?
I have some data that I have to be put in different queues and I want to avoid that I have to copy this data for each queue.
We are in a similar situation concerning the need that the objects are usually passed along as shared_ptr's but at some point need to be passed to a worker thread via a lock-free queue. To solve this problem, we allocate a copy of the shared_ptr on the heap and pass the raw pointer (to the shared_ptr) into the queue. Of course, in this case, the receiving worker thread needs to take care of deleting the heap-allocated shared_ptr. HTH, Johannes

On Fri, Feb 15, 2013 at 7:43 AM, Johannes Stallkamp
Hi Chris,
Am 14.02.2013 19:17, schrieb chris:
Hello All,
If we can't use shared_ptr in a lockfree queue, how can I share data between different queue ?
I have some data that I have to be put in different queues and I want to avoid that I have to copy this data for each queue.
We are in a similar situation concerning the need that the objects are usually passed along as shared_ptr's but at some point need to be passed to a worker thread via a lock-free queue.
To solve this problem, we allocate a copy of the shared_ptr on the heap and pass the raw pointer (to the shared_ptr) into the queue. Of course, in this case, the receiving worker thread needs to take care of deleting the heap-allocated shared_ptr.
HTH, Johannes _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Although this is only opinion, if you truly need shared_ptr, it's probably better to use std::queue and a boost::mutex unless you are absolutely sure that you require lock free data structures. The author of the library himself will tell you that it's not always faster to use the lockfree::queue than to use a std::queue with a mutex. Brian
participants (4)
-
Brian Budge
-
chris
-
Chris Herssens
-
Johannes Stallkamp