Sleeping in a Thread (C / POSIX Threads)
问题 I am developing a multithreaded application that makes use of POSIX Threads. I am using threads for doing a periodical job and for that purpose I am using usleep(3) to suspend thread execution. My question is how can I cancel usleep() timer from the main thread, I tried pthread_kill(thread, SIGALRM) but it has a global effect which results in termination of the main application (by default). Here is my pseudo code: void threaded_task(void *ptr) { initialize(); while(running) { do_the_work();