boost::thread_group in C++11?
boost::thread_group in C++11?
C++11中有类似boost::thread_group
的东西吗?
我只是试图将我的程序从使用boost:thread
移植到C++11线程,但找不到任何等效的线程。
不,在C++11中没有任何与boost::thread_group
直接等价的东西。如果你只想要一个容器,你可以使用std::vector<std::thread>
。然后,您可以使用新的for
语法或std::for_each
在每个元素上调用join()
,或者其他什么。
thread_group
没有进入C++11、C++14、C++17或C++20标准。
但解决方法很简单:
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();
}
甚至不值得封装在一个类中(但肯定是可能的)。
相关文章:
- P99_FOR in C++11
- 明确定义'static const variable in a struct'对C++ 11 及以上有什么影响吗?
- OSAtomicAdd32 variant in C++11
- std::nearbyint vs std::round in C++11
- Parsing int in C++11 - stoi
- char16_t and char32_t types in C++11
- 如果不使用C++11,安东尼威廉的"C++ Concurrency in action"是一本合适的书吗?
- 用于循环原因的新 C++11:"error: ‘begin’ was not declared in this scope"
- SIGSEGV(signal 11) 'segmentation fault' in FCTRL2 codechef
- C++11 in QtCreator 3.5.0 on ubuntu
- Using Partial Specialization in C++11
- C++ 11 in vxworks
- hash_value function in C++11
- Efficient Argmin in C++11
- boost::thread_group in C++11?
- C++11 "In class initialization"功能不适用于工会
- C++11 thread_pool, futures, promises support in gcc
- Unicode in C++11
- 使用 C+11 和 Newlib 时出现错误"sigemptyset was not declared in this scope"
- 在索引和值"for i, v in enumerate(listVar):"上是否有 C++/C++11 类似于 python 迭代?