纯C ++ 11线程池:ThreadPool

jopen 9年前

ThreadPool是一个轻量级,通用,纯C++11 线程池。

#include "ThreadPool.h"    #include <iostream>  #include <chrono>    int main() {      using nbsdx::concurrent::ThreadPool;        ThreadPool pool; // Defaults to 10 threads.      int JOB_COUNT = 100;        for( int i = 0; i < JOB_COUNT; ++i )          pool.AddJob( []() {               std::this_thread::sleep_for( std::chrono_seconds( 1 ) );          } );        pool.JoinAll();      std::cout << "Expected runtime: 10 seconds." << std::endl;  }

项目主页:http://www.open-open.com/lib/view/home/1446968025729