#include #include #include void cond_wait (pthread_cond_t *cond, pthread_mutex_t *mut) { pthread_mutex_lock(mut); pthread_cond_wait (cond, mut); pthread_mutex_unlock (mut); } void noreturn (void) { pthread_mutex_t mut; pthread_cond_t cond; pthread_mutex_init (&mut, NULL); pthread_cond_init (&cond, NULL); /* Wait for a condition that will never be signaled, so we effectively block the thread here. */ cond_wait (&cond, &mut); } void * forever_pthread (void *unused) { noreturn (); } void break_me (void) { /* Just an anchor to help putting a breakpoint. */ } int main (void) { pthread_t forever; const struct timespec ts = { 0, 10000000 }; /* 0.01 sec */ pthread_create (&forever, NULL, forever_pthread, NULL); for (;;) { nanosleep (&ts, NULL); break_me(); } return 0; }