linux 用pthread

xiaoxiao2021-02-28  44

linux 检测线程是否已经退出除了可以用pthread_kill发信号的方式,还可用pthread_tryjoin_np方式检测,前提是线程不能被设置成detached,否则函数一直返回22

bool is_thread_alive(pthread_t tid) { bool bAlive = false;         if(tid)         {             int ret = pthread_tryjoin_np(tid, NULL);             if (ret != 0) {                 /* Handle error */                 if(EBUSY == ret)                 {                     bAlive = true;                 }             }         } return bAlive; }

        

转载请注明原文地址: https://www.6miu.com/read-2630944.html

最新回复(0)