From 63dac5e737d4d9c2aadd08cf6bf0ab7e08deb580 Mon Sep 17 00:00:00 2001 From: Ole Christian Eidheim Date: Thu, 18 Jun 2015 12:35:02 +0200 Subject: [PATCH] Forgot to destroy thread in Source::Controller-destructor. --- juci/source.cc | 11 +++++++---- juci/source.h | 2 ++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/juci/source.cc b/juci/source.cc index 647483a..1c3d0df 100644 --- a/juci/source.cc +++ b/juci/source.cc @@ -259,7 +259,7 @@ HighlightToken(clang::Token *token, // Constructor for Controller Source::Controller::Controller(const Source::Config &config, const std::vector > &controllers) : - config(config), parser(controllers), parse_thread_go(false), parse_thread_mapped(false) { + config(config), parser(controllers), parse_thread_go(false), parse_thread_mapped(false), parse_thread_stop(false) { INFO("Source Controller with childs constructed"); view.signal_key_press_event().connect(sigc::mem_fun(*this, &Source::Controller::OnKeyPress), false); view.set_smart_home_end(Gsv::SMART_HOME_END_BEFORE); @@ -273,8 +273,10 @@ Source::Controller::Controller(const Source::Config &config, } Source::Controller::~Controller() { + parse_thread_stop=true; parsing.lock(); //Be sure not to destroy while still parsing with libclang parsing.unlock(); + parse_thread.join(); } void Source::Controller::OnNewEmptyFile() { @@ -357,9 +359,11 @@ void Source::Controller::OnOpenFile(const string &filepath) { } }); - std::thread parse_thread([this]() { + parse_thread=std::thread([this]() { while(true) { - while(!parse_thread_go) std::this_thread::yield(); + while(!parse_thread_go && !parse_thread_stop) std::this_thread::yield(); + if(parse_thread_stop) + break; if(!parse_thread_mapped) { parse_thread_go=false; parse_start(); @@ -373,7 +377,6 @@ void Source::Controller::OnOpenFile(const string &filepath) { } } }); - parse_thread.detach(); buffer()->signal_changed().connect([this]() { parse_thread_mapped=false; diff --git a/juci/source.h b/juci/source.h index 83816d6..a64499a 100644 --- a/juci/source.h +++ b/juci/source.h @@ -158,10 +158,12 @@ namespace Source { std::mutex parsing; Glib::Dispatcher parse_done; Glib::Dispatcher parse_start; + std::thread parse_thread; std::map parse_thread_buffer_map; std::mutex parse_thread_buffer_map_mutex; std::atomic parse_thread_go; std::atomic parse_thread_mapped; + std::atomic parse_thread_stop; const Config& config; }; // class Controller