项目作者: janlaff

项目描述 :
Threadsafe C++ Template Thread-Pool Library
高级语言: C++
项目地址: git://github.com/janlaff/libtp.git
创建时间: 2018-02-08T20:27:17Z
项目社区:https://github.com/janlaff/libtp

开源协议:GNU General Public License v3.0

下载


libtp

Examples

  1. #include <thread_pool.h>
  2. int main() {
  3. tp::thread_pool pool;
  4. for (int i = 0; i < 10; i++) {
  5. pool.post([]() {
  6. doCalcStuff();
  7. });
  8. }
  9. pool.wait();
  10. }

Example: Wait for task to finish

  1. auto myTask = pool.post([]() { doCalcStuff(); });
  2. myTask->wait(); // Blocks until myTask has finished

Example: Get task result

  1. auto myTask = pool.post<pt::future_task<std::string>>([]() {
  2. return "Result: " + calcStringValue();
  3. });
  4. // Blocks until result is available
  5. std::cout << myTask->get() << std::endl;