小编Pur*_*ixi的帖子

如何在线程中使用true?

任何人都可以指出我在这段代码中尝试做的事情,因为SecondLoop线程根本无法访问?只有删除while(true)循环才能访问它.

#include <iostream>
#include <thread>

using namespace std;

void Loop() {
    while(true) {
        (do something)
    }
}

void SecondLoop() {
    while(true) {
        (do something)
    }
}

int main() {
    thread t1(Loop);
    t1.join();

    thread t2(SecondLoop);
    t2.join(); // THIS THREAD IS UNREACHABLE AT ALL!

    return false;
}
Run Code Online (Sandbox Code Playgroud)

我使用多线程的原因是因为我需要同时运行两个循环.

c++ multithreading c++11

5
推荐指数
1
解决办法
7173
查看次数

标签 统计

c++ ×1

c++11 ×1

multithreading ×1