#include#include void foo() { // function to run in thread } int main() { boost::thread_group group; group.create_thread(&foo); group.join_all(); return 0; }
#includeIn this example, we create a thread group, add 10 threads to it that run the function `bar` with a different argument in each thread, and then wait for all threads in the group to finish before exiting the program. Boost thread_group is part of the Boost C++ Libraries package.#include void bar(int id) { // function to run in threads } int main() { boost::thread_group group; for (int i = 0; i < 10; ++i) { group.create_thread(boost::bind(&bar, i)); } group.join_all(); return 0; }