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