C ++线程池 [英] C++ Thread Pool

查看:113
本文介绍了C ++线程池的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是一个很好的开源实现对C的线程池++的生产code使用(像升压)?

What is a good open source implementation of a thread pool for C++ to use in production code (something like boost)?

请提供你自己的例子code或例如code使用的链接。

Please provide either your own example code or a link to example code usage.

推荐答案

我觉得它仍然是不被接受进入Boost,但一个好的开始点:
线程池。使用的一些例子中,从网站:

I think it is still not accepted into Boost, but a good staring point: threadpool. Some example of usage, from the web site:

#include "threadpool.hpp"

using namespace boost::threadpool;

// Some example tasks
void first_task()
{
  ...
}

void second_task()
{
  ...
}

void third_task()
{
  ...
}

void execute_with_threadpool()
{
  // Create a thread pool.
  pool tp(2);

  // Add some tasks to the pool.
  tp.schedule(&first_task);
  tp.schedule(&second_task);
  tp.schedule(&third_task);

  // Leave this function and wait until all tasks are finished.
}

变量2到池指示线程的数目。在这种情况下,的TP 毁灭等待所有线程完成。

The argument "2" to the pool indicates the number of threads. In this case, the destruction of tp waits for all threads to finish.

这篇关于C ++线程池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆