My code is:
#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);
for (int i=0; i<100; i++) {
std::cout << "from main: " << i << "\n";
}
t1.join();
return 0;
}
I create threadone that prints numbers in descending order, and mainprints in ascending order.
Sample output here . Why is my code printing garbage?
source
share