xref: /llvm-project/lldb/test/API/functionalities/thread/main_thread_exit/main.cpp (revision 4384c96fe7eb5ceb5f2c1ece4a73c22a18bac19f)
1 #include <thread>
2 
3 #ifdef __linux__
4 #include <sys/syscall.h>
5 #include <unistd.h>
6 
exit_thread(int result)7 void exit_thread(int result) { syscall(SYS_exit, result); }
8 #else
9 #error Needs OS-specific implementation
10 #endif
11 
call_me()12 int call_me() { return 12345; }
13 
thread()14 void 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()20 int main() {
21   std::thread(thread).detach();
22   exit_thread(47);
23 }
24