xen*_*ato -4 c++ multithreading pthreads c++11 stdthread
我有一个长度为N的 std::string,我想使用线程将所有长度为K 的子字符串插入到 std::set 容器中。我应该使用多少个 std::thread 或 pthread_t 对象?
考虑 N = 500,000 和 K = 3。
使用线程池。
它使用起来非常简单,您只需要这样做include "ThreadPool.h",您就可以根据可用内核数设置最大线程数。您的代码应包含以下代码段。
int max_threads = std::thread::hardware_concurrency();
ThreadPool pool(max_threads);
auto result = pool.enqueue(func,params);
Run Code Online (Sandbox Code Playgroud)
这func是要调用的函数,params参数和返回值将存储在result.