Answer the question
In order to leave comments, you need to log in
Why is the same line sometimes printed in a separate C++ thread?
Why was the unit printed twice in the 3rd line?
void foo(){
for(int i = 0; i < 5; i++){
cout << "cout " << i << endl;
}
}
int main() {
thread t(foo);
t.detach();
assert(!t.joinable());
std::cout << "Hello, World!" << std::endl;
return 0;
}
Hello, World!cout
0
cout 1cout 1
cout 2
c
Answer the question
In order to leave comments, you need to log in
most likely due to the effect of flush when calling < std::endl
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question