Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: asynchronous mode segmentation fault #856

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/easylogging++.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2297,6 +2297,9 @@ AsyncDispatchWorker::~AsyncDispatchWorker() {
setContinueRunning(false);
ELPP_INTERNAL_INFO(6, "Stopping dispatch worker - Cleaning log queue");
clean();
if (this->m_thread.joinable()) {
this->m_thread.join();
}
ELPP_INTERNAL_INFO(6, "Log queue cleaned");
}

Expand All @@ -2321,8 +2324,7 @@ void AsyncDispatchWorker::emptyQueue(void) {
void AsyncDispatchWorker::start(void) {
base::threading::msleep(5000); // 5s (why?)
setContinueRunning(true);
std::thread t1(&AsyncDispatchWorker::run, this);
t1.join();
this->m_thread = std::thread(&AsyncDispatchWorker::run, this);
}

void AsyncDispatchWorker::handle(AsyncLogItem* logItem) {
Expand Down
1 change: 1 addition & 0 deletions src/easylogging++.h
Original file line number Diff line number Diff line change
Expand Up @@ -2758,6 +2758,7 @@ class AsyncDispatchWorker : public base::IWorker, public base::threading::Thread
std::condition_variable cv;
bool m_continueRunning;
base::threading::Mutex m_continueRunningLock;
std::thread m_thread;
};
#endif // ELPP_ASYNC_LOGGING
} // namespace base
Expand Down