fix: make nCoinCacheUsage std::atomic to close an adaptive-dbcache data race
The scheduled AdjustCoinCacheForMemoryPressure task writes nCoinCacheUsage from the scheduler thread holding no lock, while cs_main-holding threads (FlushStateToDisk, VerifyDB) read it -- an unsynchronized read/write of a non-atomic size_t (C++ UB). Make it std::atomic<size_t>; correct the comment that incorrectly described the access as lock-free/race-free. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -109,7 +109,7 @@ bool fIsBareMultisigStd = true;
|
||||
bool fCheckBlockIndex = false;
|
||||
bool fCheckpointsEnabled = true;
|
||||
bool fCoinbaseEnforcedProtectionEnabled = true;
|
||||
size_t nCoinCacheUsage = 5000 * 300;
|
||||
std::atomic<size_t> nCoinCacheUsage(5000 * 300);
|
||||
uint64_t nPruneTarget = 0;
|
||||
// If the tip is older than this (in seconds), the node is considered to be in initial block download.
|
||||
int64_t nMaxTipAge = DEFAULT_MAX_TIP_AGE;
|
||||
|
||||
Reference in New Issue
Block a user