Boost logo

Boost Users :

From: dhruva (dhruvakm_at_[hidden])
Date: 2008-05-23 02:05:08


On 5/22/08, Anthony Williams <anthony.ajw_at_[hidden]> wrote:
> Chris Ross <cross+boost_at_[hidden]> writes:
>
> > Hi there. This is an introductory question as I've just started to
> > play with boost libraries. If this would be better on the threads-devel
> > list, let me know, but I thought starting here would be good.
>
>
> Here is fine.
>
>
> > I was playing with the threads library in 1.35, and I noticed that I
> > can't (with gcc 4.3 on Linux) put boost::thread objects into an STL
> > container. I think I was trying with a std::vector, in case that
> > matters.
>
>
> No, you can't do that. You need a container that can handle
> movable-but-not-copyable objects. Not only that, but it needs to
> handle the thread move emulation.

As a dirty alternative, it is possible to have the thread object
wrapped in a structure. You allocate the structure on the heap and put
that into the container. Since copying of pointers is cheap, you do
not incurr the overhead of copying in STL containers. However, you
need to free up the memory during clearing the container.
Or, even use the BOOST shared pointer, I have not used this though.

-dhruva

-- 
Contents reflect my personal views only!

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