Non-blocking pthread_join

后端 未结 8 789
一生所求
一生所求 2020-12-01 08:01

I\'m coding the shutdown of a multithreaded server.If everything goes as it should all the threads exit by their own, but there\'s a small chance that a thread gets stuck.In

相关标签:
8条回答
  • 2020-12-01 08:49

    If you're developing for QNX, you can use pthread_timedjoin() function.

    Otherwise, you can create a separate thread that will perform pthread_join() and alert the parent thread, by signalling a semaphore for example, that the child thread completes. This separate thread can return what is gets from pthread_join() to let the parent thread determine not only when the child completes but also what value it returns.

    0 讨论(0)
  • 2020-12-01 08:49

    You could push a byte into a pipe opened as non-blocking to signal to the other thread when its done, then use a non-blocking read to check the status of the pipe.

    0 讨论(0)
提交回复
热议问题