按顺序启动线程

时间:2015-11-12 10:13:34

标签: c++ multithreading

我的目标是运行一组线程,然后一旦完成,另一组线程就开始了。当我尝试运行以下代码时,我在第一组线程执行后没有发生任何事情。

我想要实现的代码如下:

int main() {

    std::vector<thread> ths;
    Gallery = new Lanes(16);
    int totalRate = redRate + blueRate;

    // Coarse grain - 1 lane at a time
    ths.push_back(std::thread(&ShooterActionCoarse,redRate,red, numRound));
    ths.push_back(std::thread(&ShooterActionCoarse,blueRate,blue, numRound));
    ths.push_back(std::thread(&CleanerCoarse));
    ths.push_back(std::thread(&Printer,totalRate));

    for (auto& th : ths) {
        th.join();
    }
    ths.clear();
    // Coarse grain - 2 lanes at a time
    ths.push_back(std::thread(&ShooterActionCoarse2,redRate,red, numRound));
    ths.push_back(std::thread(&ShooterActionCoarse2,blueRate,blue, numRound));
    ths.push_back(std::thread(&CleanerCoarse));
    ths.push_back(std::thread(&Printer,totalRate));

    for (auto& th : ths) {
        th.join();

}

0 个答案:

没有答案