|
Boost Users : |
Subject: Re: [Boost-users] [LockFree] a queue of std::shared_ptr?
From: Brian Budge (brian.budge_at_[hidden])
Date: 2013-02-15 12:43:22
On Fri, Feb 15, 2013 at 7:43 AM, Johannes Stallkamp <jstallkamp_at_[hidden]> wrote:
> 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_at_[hidden]
> 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
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