From: gg Date: Mon, 19 Jan 2026 03:21:45 +0000 (-0500) Subject: fix race condition when starting two instances at once X-Git-Url: https://git.nutra.tk/v1?a=commitdiff_plain;h=b9f1e211fe167855bbd971fe1b4b7a805e55ba19;p=gamesguru%2Ffeather.git fix race condition when starting two instances at once --- diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index 79d9ee01..3cba2857 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -68,7 +68,7 @@ Wallet::Wallet(Monero::Wallet *wallet, QObject *parent) m_coinsModel = new CoinsModel(this, m_coins); if (this->status() == Status_Ok) { - startRefreshThread(); + // startRefreshThread(); // Moved to startRefresh() // Store the wallet every 2 minutes m_storeTimer->start(2 * 60 * 1000); @@ -481,6 +481,7 @@ void Wallet::initAsync(const QString &daemonAddress, bool trustedDaemon, quint64 // #################### Synchronization (Refresh) #################### void Wallet::startRefresh() { + startRefreshThread(); m_refreshEnabled = true; m_refreshNow = true; } @@ -508,6 +509,11 @@ void Wallet::updateNetworkStatus() { void Wallet::startRefreshThread() { + bool expected = false; + if (!m_refreshThreadStarted.compare_exchange_strong(expected, true)) { + return; + } + const auto future = m_scheduler.run([this] { // Beware! This code does not run in the GUI thread. diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index 69096654..7498df47 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -546,6 +546,7 @@ private: std::atomic m_rangeSyncActive{false}; std::atomic m_syncPaused{false}; std::atomic m_lastRefreshTime{0}; + std::atomic m_refreshThreadStarted{false}; }; #endif // FEATHER_WALLET_H