From 584d057f744fee39560e35a037fec339bee2bf26 Mon Sep 17 00:00:00 2001 From: xiphon Date: Tue, 12 Nov 2019 16:05:17 +0000 Subject: [PATCH] epee: fix console_handlers_binder race, wait for thread to finish --- contrib/epee/include/console_handler.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/contrib/epee/include/console_handler.h b/contrib/epee/include/console_handler.h index 13747b0c8..1b716fca4 100644 --- a/contrib/epee/include/console_handler.h +++ b/contrib/epee/include/console_handler.h @@ -605,10 +605,17 @@ eof: std::unique_ptr m_console_thread; async_console_handler m_console_handler; public: + ~console_handlers_binder() { + stop_handling(); + if (m_console_thread.get() != nullptr) + { + m_console_thread->join(); + } + } + bool start_handling(std::function prompt, const std::string& usage_string = "", std::function exit_handler = NULL) { m_console_thread.reset(new boost::thread(boost::bind(&console_handlers_binder::run_handling, this, prompt, usage_string, exit_handler))); - m_console_thread->detach(); return true; } bool start_handling(const std::string &prompt, const std::string& usage_string = "", std::function exit_handler = NULL)