任何人都可以指出我在这段代码中尝试做的事情,因为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)
我使用多线程的原因是因为我需要同时运行两个循环.