Is there some standard Threadpool library

Is there some standard threadpool (wikipedia.org/wiki/Thread_pool) library


As far I can tell STL does not provide one, and boost provides one, but their documentation does not include examples, can someone let me know if there is some STL implementation

anyway please provide a simple example of using a threadpool library
Actually boost does provide i handy example here:
https://www.boost.org/doc/libs/1_76_0/doc/html/boost_asio/reference/static_thread_pool.html


Here is also an extra example I managed to make out (hope it is useful)

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <boost/asio.hpp>

int main() {
	const uint core_count = 2;
	boost::asio::thread_pool pool(core_count);
	for (int j = 50; j != 0; j--)
		boost::asio::post(pool,[=](){
			for (int i = 0xfffffff; i != 0; i--);//busy waiting
			std::cout << "done" << j << std::endl;
		});
	pool.join();
}


BESURE TO COMPILE WITH THE -pthread flag (this took me a while to figure out)
 
g++ test.cpp -pthread && ./a.out
Last edited on
Topic archived. No new replies allowed.