Subject: Re: [boost] boost atomic question
From: Andras Erdei (aerdei_at_[hidden])
Date: 2010-05-04 12:15:47
On Fri, Apr 30, 2010 at 5:04 PM, Janek Kozicki <janek_listy_at_[hidden]> wrote:
> Hello Helge,
> What would it take to get this code to work?
> std::vector<boost::atomic<Something> > v;
It'll never work: atomic<T> has a deleted copy constructor, and
standard containers only work with copyable types.
For atomic<T> to work, T must be trivially copyable (basically it must
be a POD).
Unless T is small (<= 64 bits) i'd expect atomic<T> to be implemented
with a (per-object) mutex, but:
'atomic<T>' only supports a few operations (it does not reexport T's
interface), so you'd have to reimplement your methods in terms of that
limited set operations. If you are not familiar with lock-free coding
you might be better off explicitly adding a mutex to 'Something', and
implementing your methods the traditional way.