man _exit
C library/kernel differences
In glibc up to version 2.3, the _exit() wrapper function invoked the kernel system call of the same name. Since
glibc 2.3, the wrapper function invokes exit_group(2), in order to terminate all of the threads in a process. (The
raw _exit() system call terminates only the calling thread.)
#include<thread>intmain(){
std::thread([]{while(true){}}).detch();usingnamespace std::chrono_literals;
std::this_thread::sleep_for(10s);/* after 10s, main exit, thread above also exit */}
futex
man futex
Note: There is no glibc wrapper for this system call; see NOTES.
static long futex(uint32_t *uaddr, int futex_op, uint32_t val,
const struct timespec *timeout, uint32_t *uaddr2,
uint32_t val3);
FUTEX_WAIT: => *uaddr == val =>sleep
FUTEX_WAKE => modify *uaddr by read-modify-write, then futex(uaddr, FUTEX_WAKE, 1)# if *uaddr = 1