Boost 1.35 threads library question

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. 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. I was reading in some of the C++0x documents that it's expected that the standard library thread implementation is expected to be able to have this work. The boost documentation doesn't explicitly say whether it should work or not. Is being non-copyable but movable enough to make this work? Or, would an object have to be copyable to be put into an STL container? I thought that was not the case, but. Thanks... - Chris

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.
You may be interested in the thread_group http://www.boost.org/doc/libs/1_35_0/doc/html/thread.html Also check out http://threadpool.sourceforge.net/ James

On Thu, 2008-05-22 at 09:51 -0600, James Sutherland wrote:
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.
You may be interested in the thread_group http://www.boost.org/doc/libs/1_35_0/doc/html/thread.html Also check out http://threadpool.sourceforge.net/
thread_group doesn't allow me to iterate the group. It only will allow me to join_all or interrupt_all, but not perform arbitrary actions on all of them, or iterate them so I can do whatever I need/want... I was mostly inquiring because it was suggested that it should work in the upcoming standards, so I was wondering if it was supposed to work in boost 1.35. - Chris

Chris Ross
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.
I was reading in some of the C++0x documents that it's expected that the standard library thread implementation is expected to be able to have this work. The boost documentation doesn't explicitly say whether it should work or not. Is being non-copyable but movable enough to make this work? Or, would an object have to be copyable to be put into an STL container? I thought that was not the case, but.
Non-copyable but movable is indeed enough for a class to be used in a C++0x STL container. I don't know whether the containers with gcc 4.3 have that support in -std=c++0x mode or not. The current trunk has some rvalue reference support in boost::thread, so it may well work, but I haven't tried it. Anthony -- Anthony Williams | Just Software Solutions Ltd Custom Software Development | http://www.justsoftwaresolutions.co.uk Registered in England, Company Number 5478976. Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL

On 5/22/08, Anthony Williams
Chris Ross
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!
participants (4)
-
Anthony Williams
-
Chris Ross
-
dhruva
-
James Sutherland