Skip to content

A simple C++11 Thread Pool implementation 用C++11实现一个简单的线程池,添加详细注释

License

Notifications You must be signed in to change notification settings

Seaworth/ThreadPool

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

线程池ThreadPool

C++11来实现一个简单的线程池。

基本用法:

// 创建带有4个工作线程的线程池
// create thread pool with 4 worker threads
ThreadPool pool(4);

// 将任务压入工作队列,线程处理后的结果保存在future中
// enqueue and store future
auto result = pool.enqueue([](int answer) { return answer; }, 42);

// 从future中获得线程处理后的结果
// get result from future
std::cout << result.get() << std::endl;

源码中用到了许多C++11的特性,需要了解以下的知识点,能够更清晰地理解实现的过程:

一些有参考意义的博客:

  1. C++11的简单线程池代码阅读
  2. 分享一个C++11写的线程池

About

A simple C++11 Thread Pool implementation 用C++11实现一个简单的线程池,添加详细注释

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 100.0%