24 lines · cpp
1#include <thread>2 3#ifdef __linux__4#include <sys/syscall.h>5#include <unistd.h>6 7void exit_thread(int result) { syscall(SYS_exit, result); }8#else9#error Needs OS-specific implementation10#endif11 12int call_me() { return 12345; }13 14void thread() {15 std::this_thread::sleep_for(16 std::chrono::seconds(10)); // Let the main thread exit.17 exit_thread(42); // break here18}19 20int main() {21 std::thread(thread).detach();22 exit_thread(47);23}24