Closed nqf closed 4 years ago
线程池中采用一个线程
int NUM = 10000; { ThreadPool pool(1); auto start = getTimeStamp<std::chrono::milliseconds>(); std::vector<std::future<void>> results; for (int i = 1; i <= NUM; ++i) { results.emplace_back( pool.enqueue([i, &start, &NUM] { if (i == NUM) { std::cout << "thread_pool time:" << getTimeStamp<std::chrono::milliseconds>() - start << std::endl; } })); } for (auto &ret : results) ret.wait(); std::cout << "thread_pool time:" << getTimeStamp<std::chrono::milliseconds>() - start << std::endl; } std::cout << "开始libgo" << std::endl; { auto start = getTimeStamp<std::chrono::milliseconds>(); for (int i = 1; i <= NUM; i++) { go[i, &start, &NUM] { if (i == NUM) { std::cout << "libgo time:" << getTimeStamp<std::chrono::milliseconds>() - start << std::endl; } }; } } thread_pool time:23 thread_pool time:23 开始libgo libgo time:74
线程池中采用一个线程