[LockFree] a queue of std::shared_ptr?
Hi all, Is it possible to store std::shared_ptr objects in a boost::lockfree::queue? eg. boost::lockfree::queue<std::shared_ptr<Message>> q; gcc 4.7.2 with Boost 1.53.0 is giving a static assertion failure. It wants: boost::has_trivial_destructor<T>::value and boost::has_trivial_assign<T>::value Any help would be muchly appreciated. Scott.
On 02/11/2013 04:04 PM, Scott Smedley wrote:
Hi all,
Is it possible to store std::shared_ptr objects in a boost::lockfree::queue?
eg. boost::lockfree::queue<std::shared_ptr<Message>> q;
gcc 4.7.2 with Boost 1.53.0 is giving a static assertion failure. It wants: boost::has_trivial_destructor<T>::value and boost::has_trivial_assign<T>::value
Any help would be muchly appreciated.
Scott.
Hi Scott - Lockfree queues require that the queued type (T) meets the following requirements: o T must have a copy constructor o T must have a trivial assignment operator o T must have a trivial destructor shared_ptr has neither a trivial assignment operator or destructor and cannot be used in the lockfree containers. michael -- Michael Caisse ciere consulting ciere.com
2013/2/12 Michael Caisse <mcaisse-lists@ciere.com>
On 02/11/2013 04:04 PM, Scott Smedley wrote:
Hi all,
Is it possible to store std::shared_ptr objects in a boost::lockfree::queue?
eg. boost::lockfree::queue<std::**shared_ptr<Message>> q;
Hi Scott -
Lockfree queues require that the queued type (T) meets the following requirements:
o T must have a copy constructor o T must have a trivial assignment operator o T must have a trivial destructor
shared_ptr has neither a trivial assignment operator or destructor and cannot be used in the lockfree containers.
michael
Hello, I'm curious: suppose T is a type, that meets requirements for lockfree queues. Does optional<T> meet those requirements? a) Does optional<T> have a copy constructor? Yes. b) Does optional<T> have a trivial assignment operator? Well, the assignment is user-written in optional, but it's observable effect is equivalent to memcpy, isn't it? c) Does optional<T> have a trivial destructor? Well, optional's destructor conditionally calls T's destructor, which is trivial. So is a destructor trivial, if all it does is conditionally call a trivial destructor? Regards, Kris
On Fri, Feb 22, 2013 at 8:14 AM, Krzysztof Czainski <1czajnik@gmail.com>wrote:
2013/2/12 Michael Caisse <mcaisse-lists@ciere.com>
On 02/11/2013 04:04 PM, Scott Smedley wrote:
Hi all,
Is it possible to store std::shared_ptr objects in a boost::lockfree::queue?
eg. boost::lockfree::queue<std::**shared_ptr<Message>> q;
Hi Scott -
Lockfree queues require that the queued type (T) meets the following requirements:
o T must have a copy constructor o T must have a trivial assignment operator o T must have a trivial destructor
shared_ptr has neither a trivial assignment operator or destructor and cannot be used in the lockfree containers.
michael
Hello,
I'm curious: suppose T is a type, that meets requirements for lockfree queues. Does optional<T> meet those requirements?
a) Does optional<T> have a copy constructor? Yes. b) Does optional<T> have a trivial assignment operator? Well, the assignment is user-written in optional, but it's observable effect is equivalent to memcpy, isn't it? c) Does optional<T> have a trivial destructor? Well, optional's destructor conditionally calls T's destructor, which is trivial. So is a destructor trivial, if all it does is conditionally call a trivial destructor?
This is true in theory for an optional implementation like boost::optional, which uses a boolean flag to indicate initialization state, though I'd doubt all the necessary type traits are specialized for boost::optional. However, an optional implementation that uses a pointer to indicate initialization state (null pointer indicates uninitialized, otherwise pointer points to internal buffer; thus, get_ptr() just returns the pointer) would not have a trivial copy constructor and assignment operator, and I think technically, whether boost::optional uses a boolean flag or a pointer is an implementation detail. - Jeff
2013/2/22 Jeffrey Lee Hellrung, Jr. <jeffrey.hellrung@gmail.com>
On Fri, Feb 22, 2013 at 8:14 AM, Krzysztof Czainski <1czajnik@gmail.com>wrote:
2013/2/12 Michael Caisse <mcaisse-lists@ciere.com>
On 02/11/2013 04:04 PM, Scott Smedley wrote:
Hi all,
Is it possible to store std::shared_ptr objects in a boost::lockfree::queue?
eg. boost::lockfree::queue<std::**shared_ptr<Message>> q;
Hi Scott -
Lockfree queues require that the queued type (T) meets the following requirements:
o T must have a copy constructor o T must have a trivial assignment operator o T must have a trivial destructor
shared_ptr has neither a trivial assignment operator or destructor and cannot be used in the lockfree containers.
michael
Hello,
I'm curious: suppose T is a type, that meets requirements for lockfree queues. Does optional<T> meet those requirements?
a) Does optional<T> have a copy constructor? Yes. b) Does optional<T> have a trivial assignment operator? Well, the assignment is user-written in optional, but it's observable effect is equivalent to memcpy, isn't it? c) Does optional<T> have a trivial destructor? Well, optional's destructor conditionally calls T's destructor, which is trivial. So is a destructor trivial, if all it does is conditionally call a trivial destructor?
This is true in theory for an optional implementation like boost::optional, which uses a boolean flag to indicate initialization state, though I'd doubt all the necessary type traits are specialized for boost::optional. However, an optional implementation that uses a pointer to indicate initialization state (null pointer indicates uninitialized, otherwise pointer points to internal buffer; thus, get_ptr() just returns the pointer) would not have a trivial copy constructor and assignment operator, and I think technically, whether boost::optional uses a boolean flag or a pointer is an implementation detail.
- Jeff
Ok, that makes sense. Cheers, Kris
participants (4)
-
Jeffrey Lee Hellrung, Jr.
-
Krzysztof Czainski
-
Michael Caisse
-
Scott Smedley