General Category > General Discussion about just::thread
std::vector<std::thread> example from Concurrency in action
Anthony Williams:
--- Quote from: Kenneth Carter on November 25, 2008, 06:01:13 PM ---the above sample would still not work. what I have found that works if I use a raw array pointer of std::thread *ptr_threads = new std::thread[ num_threads - 1 ].
the only draw back is that I have to remember to clean it up with delete [] ptr_threads.
--- End quote ---
Yes, I tried it. The code that requires the copy constructor is in the allocator, and is not actually used in this example, but it is required to compile. I'll see if I can figure out a way to write a custom allocator that allows this to work.
Anthony Williams:
--- Quote from: Anthony Williams on November 25, 2008, 06:06:59 PM ---The code that requires the copy constructor is in the allocator, and is not actually used in this example, but it is required to compile. I'll see if I can figure out a way to write a custom allocator that allows this to work.
--- End quote ---
With a small amount of code, it is possible to make std::vector<std::thread> work for fixed-sized vectors, but you cannot call resize(), push_back(), erase(), insert() or clear(). You can't even call swap(). I'm not sure it's worth it - what we really need is a move-aware vector implementation.
Kenneth Carter:
I would agree with you on this point. so what we would need is a move aware vector list. can you post links to the necesary information so if i were to persue development of a move aware container like vector or a custom array class. I would at least have the information to do so.
Kenneth
Anthony Williams:
--- Quote from: Kenneth Carter on November 28, 2008, 06:48:04 PM ---I would agree with you on this point. so what we would need is a move aware vector list. can you post links to the necesary information so if i were to persue development of a move aware container like vector or a custom array class. I would at least have the information to do so.
--- End quote ---
The C++0x working draft is at http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf. std::vector is described in chapter 23.2.6.
In order to support my implementation of std::thread (and other movable types such as std::unique_future<> and std::packaged_task<>) on MSVC 2008, you will need to handle types that convert to __jss::move_emulation_t<T> differently from "normal" types and move them rather than copy them.
Anthony Williams:
Support for std::vector<std::thread> will be in the 0.6 beta later this week.
Navigation
[0] Message Index
[*] Previous page
Go to full version