c++ condition variable notification not working as expected
std::async
returns a std::future
holding result of function execution. In your case, it is a temporary object which is immideatly destroyed. The documentation for std::future
says:
✔ the shared state was created by a call to std::async
✔ the shared state is not yet ready
✔ this was the last reference to the shared state
All of those are true, so destruction of that future
will block until worker function will finish executing.
You can create detached thread to avoid this problem:
std::thread(worker_thread).detach();