The destructor for std::thread will call std::terminate if it is running on the thread, if you did not call join() (to wait for the thread to finish) or detach() (to disconnect 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 called. This is not due to the presence of condition variables.
Mankarse
source share