我的代码:为什么我的程序打印垃圾?
#include <iostream>
#include <thread>
void function_1()
{
std::cout << "Thread t1 started!\n";
for (int j=0; j>-100; j--) {
std::cout << "t1 says: " << j << "\n";
}
}
int main()
{
std::thread t1(function_1); // t1 starts running
for (int i=0; i<100; i++) {
std::cout << "from main: " << i << "\n";
}
t1.join(); // main thread waits for t1 to finish
return 0;
}
我同时为了提高打印main
递减的顺序创建thread
,打印数量。
样品输出here。为什么我的代码打印垃圾?
我不确定你为什么不能访问它。这是一个公众的主旨。 – SPV