What happens when calling the destructor of a thread object that has a condition variable waiting?

后端 未结 3 1652
遇见更好的自我
遇见更好的自我 2020-12-06 02:38

I am using a SynchronisedQueue to communicate between threads. I found that destroying the thread object when the attaching thread is waiting on a condition var

3条回答
  •  执念已碎
    2020-12-06 03:23

    The destructor for std::thread will call std::terminate if it is run on a thread if you not have called join() (to wait the thread to finish) or detach() (to detach the thread from the object) on it.

    Your code calls the destructor for worker_thread without calling join() or detach() on it, and so std::terminate is called. This is unrelated to the presence of condition variables.

提交回复
热议问题