I want to make a thread sleep for an indefinite amount of time. The reason I want to do this is because my program only takes action when it receives a signal and has nothing to do in the primary thread. Therefore, all processing is done inside the signal handler. How can I sleep for an indefinite amount of time?
sleep() function does not cease a specific thread, but it stops the whole process for the specified amount of time. For stopping the execution of a particular thread, we can use one pthread condition object and use pthread_cond_timedwait() function for making the thread wait for a specific amount of time.
The sleep() method in the C programming language allows you to wait for just a current thread for a set amount of time. The sleep() function will sleep the present executable for the time specified by the thread. Presumably, the CPU and other operations will function normally.
The sleep function waits for seconds seconds or until a signal is delivered, whichever happens first. If sleep returns because the requested interval is over, it returns a value of zero. If it returns because of delivery of a signal, its return value is the remaining time in the sleep interval.
I believe you're looking for the pause
function:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pause.html
You could do something like: for (;;) pause();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With