pthread_cond_wait: random segmentation fault

后端 未结 3 901
[愿得一人]
[愿得一人] 2021-01-25 03:07

Update 3

recently, I noticed that my code randomly causes Segmentation Fault errors. But I think that my code is pretty simple so far and I cant figure out wh

3条回答
  •  死守一世寂寞
    2021-01-25 03:53

    It looks as if you're unlocking your termination_in_process mutex from your main process - even though it was locked by another thread - which is undefined behavior. It might work, and it might not work.

    A solution could be to use a FIFO buffer (for instance a std::queue, or even just a std::vector) and push the thread id of your terminated threads to it in your Exit() function, then send out your signal, and let the main thread go through the buffer and join any threads in it.

    If Exit() isn't called at the point of your segfault this shouldn't be the reason for your problem though, but it's still something you might want to fix.

提交回复
热议问题