how to declare a vector of thread

前端 未结 2 1334
名媛妹妹
名媛妹妹 2021-01-26 12:58

i\'m new in c++ programing and need some help to use a thread library with vector library...

first I follow this tutorial

but the compiler (visual studio 2013) s

相关标签:
2条回答
  • 2021-01-26 13:02

    finally I can solve the problem with this change in my code...

    workers.emplace_back(thread{ [&]() {
        calcIterThread(ref(res), inicio, fin, i);
    }});
    
    0 讨论(0)
  • 2021-01-26 13:07

    Try this:

    #include <functional>
    #include <thread>
    #include <vector>
    
    // ...
    
    int numThreads = 10;
    std::vector<std::thread> workers;
    
    for (int i = 0; i != numThreads; ++i)
    {
        workers.emplace_back(calcIterThread, std::ref(res), inicia, fin, i);
    }
    
    for (auto & t : workers)
    {
        t.join(); 
    }
    
    0 讨论(0)
提交回复
热议问题