Non-blocking pthread_join

后端 未结 8 828
一生所求
一生所求 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:45

    I'm not sure what exactly you mean, but I'm assuming that what you really need is a wait and notify mechanism.

    In short, here's how it works: You wait for a condition to satisfy with a timeout. Your wait will be over if:

    • The timeout occurs, or
    • If the condition is satisfied.

    You can have this in a loop and add some more intelligence to your logic. The best resource I've found for this related to Pthreads is this tutorial: POSIX Threads Programming (https://computing.llnl.gov/tutorials/pthreads/).

    I'm also very surprised to see that there's no API for timed join in Pthreads.

提交回复
热议问题