Keep track of notifier thread to make sure it exits before `notify_thread` struct is freed

pull/208/head
jackun 4 years ago
parent 31f9cce720
commit 467c53d22f
No known key found for this signature in database
GPG Key ID: 119DB3F1D05A9ED3

@ -33,7 +33,7 @@ static void fileChanged(void *params_void) {
}
}
i = 0;
std::this_thread::sleep_for(std::chrono::milliseconds(10));
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
@ -52,7 +52,9 @@ bool start_notifier(notify_thread& nt)
return false;
}
std::thread(fileChanged, &nt).detach();
if (nt.thread.joinable())
nt.thread.join();
nt.thread = std::thread(fileChanged, &nt);
return true;
}
@ -62,6 +64,8 @@ void stop_notifier(notify_thread& nt)
return;
nt.quit = true;
if (nt.thread.joinable())
nt.thread.join();
inotify_rm_watch(nt.fd, nt.wd);
close(nt.fd);
nt.fd = -1;

@ -8,6 +8,7 @@ struct notify_thread
overlay_params *params = nullptr;
bool quit = false;
std::mutex mutex;
std::thread thread;
};
bool start_notifier(notify_thread& nt);

Loading…
Cancel
Save