https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98108
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> --- I think this is undefined since global object initialization order is not well-defined between TUs so thread1/thread2 and std::cout construction are not well-ordered. It probably works (by accident) when doing g++ -pthread file2.cc file1.cc