1*4384c96fSPavel Labath #include <thread> 2*4384c96fSPavel Labath 3*4384c96fSPavel Labath #ifdef __linux__ 4*4384c96fSPavel Labath #include <sys/syscall.h> 5*4384c96fSPavel Labath #include <unistd.h> 6*4384c96fSPavel Labath exit_thread(int result)7*4384c96fSPavel Labathvoid exit_thread(int result) { syscall(SYS_exit, result); } 8*4384c96fSPavel Labath #else 9*4384c96fSPavel Labath #error Needs OS-specific implementation 10*4384c96fSPavel Labath #endif 11*4384c96fSPavel Labath call_me()12*4384c96fSPavel Labathint call_me() { return 12345; } 13*4384c96fSPavel Labath thread()14*4384c96fSPavel Labathvoid thread() { 15*4384c96fSPavel Labath std::this_thread::sleep_for( 16*4384c96fSPavel Labath std::chrono::seconds(10)); // Let the main thread exit. 17*4384c96fSPavel Labath exit_thread(42); // break here 18*4384c96fSPavel Labath } 19*4384c96fSPavel Labath main()20*4384c96fSPavel Labathint main() { 21*4384c96fSPavel Labath std::thread(thread).detach(); 22*4384c96fSPavel Labath exit_thread(47); 23*4384c96fSPavel Labath } 24