Use condition_variable for interruptible thread sleep in updateLoop#147
Open
jslauthor wants to merge 1 commit intoCountly:masterfrom
Open
Use condition_variable for interruptible thread sleep in updateLoop#147jslauthor wants to merge 1 commit intoCountly:masterfrom
jslauthor wants to merge 1 commit intoCountly:masterfrom
Conversation
Replace std::this_thread::sleep_for() in updateLoop() with std::condition_variable::wait_for() so that _deleteThread() can wake the background thread immediately via notify_one(). This makes stop() return instantly instead of blocking for up to the full update interval (e.g. 30 seconds in production builds). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Author
|
Sorry, accidentally created this. Will open again if needed! |
Author
|
Okay, I do need it. 😅 This lets us cancel any pending requests so the app can close cleanly. Let me know if you'd like any changes! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
std::this_thread::sleep_for()inupdateLoop()withstd::condition_variable::wait_for()stop_cv.notify_one()in_deleteThread()to wake the sleeping thread immediatelyThis makes
stop()return instantly instead of blocking for up to the full update interval (e.g. 30 seconds). Currently,_deleteThread()setsstop_thread = trueand callsthread->join(), but the thread is stuck inside an uninterruptiblesleep_for()and won't check the flag until the sleep finishes.This causes GUI applications to hang for up to 30 seconds on quit when the SDK's static singleton destructor calls
stop().Changes
include/countly.hpp#include <condition_variable>std::condition_variable stop_cvmembersrc/countly.cppupdateLoop(): Replacedsleep_forwithstop_cv.wait_for()usingstop_threadas predicate_deleteThread(): Addedstop_cv.notify_one()after settingstop_thread = trueTest plan
stop()returns instantly instead of blocking