how to terminate a sleeping thread in pthread?

后端 未结 3 987
春和景丽
春和景丽 2021-02-04 16:30

I have thread which sleeps for a long time, then wakes up to do something, then sleep again, like this:

while(some_condition)
{
    // do something
    sleep(100         


        
3条回答
  •  广开言路
    2021-02-04 16:36

    As an alternative to sleep, you could use pthread_cond_timedwait with a 1000 ms timeout. Then when you want to exit, signal the condition variable.

    This is similar to how you might do this in C#/Java using wait and notify.

提交回复
热议问题