Non-blocking pthread_join

后端 未结 8 831
一生所求
一生所求 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条回答
  •  旧时难觅i
    2020-12-01 08:36

    If you are running your application on Linux, you may be interested to know that:

    int pthread_tryjoin_np(pthread_t thread, void **retval);
    
    int pthread_timedjoin_np(pthread_t thread, void **retval,
                                    const struct timespec *abstime);
    

    Be careful, as the suffix suggests it, "np" means "non-portable". They are not POSIX standard, gnu extensions, useful though.

    link to man page

提交回复
热议问题