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