2
#include <iostream>
#include <thread>

void f() {
    std::cout << "hello" << std::endl;
}

int main() {
    std::thread(f);
    while(true) {}
}

Running above code hangs forever as I expected, but it doesn't print anything. if thread(f) is replaced with thread t(f), it prints hello. Does this mean my compiler has a bug? I'm using gcc 7.2.1 on arch linux.

einpoklum
  • 118,144
  • 57
  • 340
  • 684
frank
  • 89
  • 1
  • 6

0 Answers0