Non-blocking pthread_join

后端 未结 8 827
一生所求
一生所求 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.

提交回复
热议问题