Is there anything like boost::thread_group
in C++11?
I'm just trying to port my program from using boost:thread
to C++11 threads and wasn't able to find anything equivalent.
Thread enables the use of multiple threads of execution with shared data in portable C++ code.
“Boost Fiber” is a library designed to provide very light weight thread (fiber) support in user mode. A single thread can support multiple fibers that are scheduled using a fiber level scheduler running within a single thread.
Since boost is mainly just a wrapper around pthreads (on posix platforms) it helps to know what is going on underneath. In attempting to be generic, boost leaves the platform specific functionality unwrapped. In order to get to it you need to use the native_handle() calls.
No, there's nothing directly equivalent to boost::thread_group
in C++11. You could use a std::vector<std::thread>
if all you want is a container. You can then use either the new for
syntax or std::for_each
to call join()
on each element, or whatever.
thread_group
didn't make it into C++11, C++14, C++17 or C++20 standards.
But a workaround is simple:
std::vector<std::thread> grp; // to create threads grp.emplace_back(functor); // pass in the argument of std::thread() void join_all() { for (auto& thread : grp) thread.join(); }
Not even worth wrapping in a class (but is certainly possible).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With