fix(mining): make XmrigManager's thread count atomic
The requested thread count is written by generateConfig() on the mining-control thread and read on the UI thread (the thread-grid sync under idle thread scaling, the pool auto-balance restart) without any synchronisation. The write also stored the unclamped count first and clamped it afterwards, so a reader could see more threads than cores. It is now an atomic, set by one store of the clamped value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -173,9 +173,10 @@ bool XmrigManager::generateConfig(const Config& cfg, const std::string& outPath)
|
||||
|
||||
int hw = (int)std::thread::hardware_concurrency();
|
||||
if (hw < 1) hw = 1;
|
||||
// Use explicit thread count (not just a hint)
|
||||
threads_ = (cfg.threads > 0) ? cfg.threads : std::max(1, hw / 2);
|
||||
if (threads_ > hw) threads_ = hw;
|
||||
// Use explicit thread count (not just a hint). One store: the UI thread reads it (getRequestedThreads).
|
||||
int t = (cfg.threads > 0) ? cfg.threads : std::max(1, hw / 2);
|
||||
if (t > hw) t = hw;
|
||||
threads_ = t;
|
||||
|
||||
json j;
|
||||
j["autosave"] = false;
|
||||
@@ -324,7 +325,7 @@ bool XmrigManager::start(const Config& cfg) {
|
||||
return false;
|
||||
}
|
||||
DEBUG_LOGF("[INFO] XmrigManager: config written to %s (API port %d, threads %d)\n",
|
||||
cfgPath.c_str(), api_port_, threads_);
|
||||
cfgPath.c_str(), api_port_, threads_.load());
|
||||
|
||||
// Spawn process
|
||||
if (!startProcess(binary, cfgPath, threads_)) {
|
||||
|
||||
@@ -173,7 +173,7 @@ private:
|
||||
// xmrig HTTP API credentials (random per session)
|
||||
int api_port_ = 0;
|
||||
std::string api_token_;
|
||||
int threads_ = 0; // Thread count for mining
|
||||
std::atomic<int> threads_{0}; // Thread count for mining (written on the mining-control thread, read by the UI)
|
||||
std::string pool_host_; // Pool hostname for stats API
|
||||
PoolStats stats_;
|
||||
mutable std::mutex stats_mutex_;
|
||||
|
||||
Reference in New Issue
Block a user