相关疑难解决方法(0)

C++ 11中的线程池

相关问题:

关于C++ 11:

关于Boost:


我如何获得一个线程池,以任务发送到,而无需创建和删除它们一遍又一遍?这意味着要在不加入的情况下重新同步的持久线程.


我的代码看起来像这样:

namespace {
  std::vector<std::thread> workers;

  int total = 4;
  int arr[4] = {0};

  void each_thread_does(int i) {
    arr[i] += 2;
  }
}

int main(int argc, char *argv[]) {
  for (int i = 0; i < 8; ++i) { // for 8 iterations,
    for (int j = 0; j < 4; ++j) {
      workers.push_back(std::thread(each_thread_does, j));
    }
    for (std::thread &t: …
Run Code Online (Sandbox Code Playgroud)

c++ multithreading threadpool c++11 stdthread

113
推荐指数
6
解决办法
17万
查看次数

在linux上学习线程

Linux对我来说是一个新平台.我已经用c ++在Windows上编码了很多年,并且已经适应了该平台上的多线程.

当我需要在linux平台上学习c ++时,C++ 11就出现了.

Linux似乎在大多数情况下使用pthreads - 好吧还有boost :: threads和QT也有自己的线程.但是随着C++ 11出现了std :: thread,一种全新的(跨平台和C++标准)做线程的方式.

所以我想我将不得不学习pthreads和std :: threads.最终,std :: thread似乎更重要,但那里有很多遗留代码,所以我必须知道两者.

对于Windows上的线程同步,我将使用WaitForMultipleObjects等待许多任务完成,然后继续进一步的工作.

pthreads是否存在类似的同步机制?的std ::线程?

我已经看过pthread_join了,它似乎只能在一个线程上等待一次.我可能错过了另一个pthread电话吗?

c++ linux pthreads c++11 stdthread

3
推荐指数
1
解决办法
2060
查看次数

标签 统计

c++ ×2

c++11 ×2

stdthread ×2

linux ×1

multithreading ×1

pthreads ×1

threadpool ×1