Is there an invalid pthread_t id?

前端 未结 6 2053
说谎
说谎 2020-12-13 05:43

I would like to call pthread_join for a given thread id, but only if that thread has been started. The safe solution might be to add a variable to track which thread where s

6条回答
  •  离开以前
    2020-12-13 06:22

    I was porting some code that used pthreads into a C++ application, and I had the same question. I decided it was easier to switch to the C++ std::thread object, which has the .joinable() method to decide whether or not to join, i.e.

     if (t.joinable()) t.join();
    

    I found that just calling pthead_join on a bad pthread_t value (as a result of pthread_create failing) caused a seg fault, not just an error return value.

提交回复
热议问题