1*df4ad362SPavel Labath #include "pseudo_barrier.h" 2*df4ad362SPavel Labath #include <cstdlib> 3*df4ad362SPavel Labath #include <thread> 4*df4ad362SPavel Labath 5*df4ad362SPavel Labath // Use low-level exit functions to achieve predictable timing. 6*df4ad362SPavel Labath #if defined(__linux__) 7*df4ad362SPavel Labath #include <sys/syscall.h> 8*df4ad362SPavel Labath #include <unistd.h> 9*df4ad362SPavel Labath exit_thread(int status)10*df4ad362SPavel Labathvoid exit_thread(int status) { syscall(SYS_exit, status); } exit_process(int status)11*df4ad362SPavel Labathvoid exit_process(int status) { syscall(SYS_exit_group, status); } 12*df4ad362SPavel Labath #else 13*df4ad362SPavel Labath #error Unimplemented 14*df4ad362SPavel Labath #endif 15*df4ad362SPavel Labath 16*df4ad362SPavel Labath pseudo_barrier_t g_barrier; 17*df4ad362SPavel Labath thread_func()18*df4ad362SPavel Labathvoid thread_func() { 19*df4ad362SPavel Labath pseudo_barrier_wait(g_barrier); 20*df4ad362SPavel Labath exit_thread(42); 21*df4ad362SPavel Labath } 22*df4ad362SPavel Labath main()23*df4ad362SPavel Labathint main() { 24*df4ad362SPavel Labath pseudo_barrier_init(g_barrier, 2); 25*df4ad362SPavel Labath std::thread(thread_func).detach(); 26*df4ad362SPavel Labath 27*df4ad362SPavel Labath pseudo_barrier_wait(g_barrier); 28*df4ad362SPavel Labath 29*df4ad362SPavel Labath exit_process(47); 30*df4ad362SPavel Labath } 31