@@ -61,19 +61,25 @@ void Miner::reload() {
61
61
manager->releaseStats (); // not needed anymore
62
62
}
63
63
64
+ void shutdown () {
65
+ if (!Signals::HALT) {
66
+ Log::get ().info (" Signaling shutdown" );
67
+ Signals::HALT = true ;
68
+ }
69
+ }
70
+
64
71
void Miner::mine () {
65
72
if (progress_monitor) {
66
73
// start background thread for progress monitoring
67
74
auto monitor = progress_monitor;
68
- std::thread thread ([monitor]() {
75
+ std::thread monitor_thread ([monitor]() {
69
76
const auto delay = std::chrono::seconds (36 ); // 1% steps (magic number)
70
77
while (!monitor->isTargetReached () && !Signals::HALT) {
71
78
monitor->writeProgress ();
72
79
std::this_thread::sleep_for (delay);
73
80
}
74
81
monitor->writeProgress (); // final write
75
- Log::get ().info (" Initiating shutdown" );
76
- Signals::HALT = true ;
82
+ shutdown ();
77
83
});
78
84
79
85
try {
@@ -86,15 +92,16 @@ void Miner::mine() {
86
92
auto mins = std::to_string (monitor->getElapsedSeconds () / 60 );
87
93
Log::get ().info (" Finished mining after " + mins + " minutes" );
88
94
} catch (const std::exception &e) {
89
- Log::get ().error (" Caught exception during initialization or mining: " +
90
- std::string (e.what ()),
91
- false );
92
- } catch (...) {
93
95
Log::get ().error (
94
- " Caught unknown exception during initialization or mining" , false );
96
+ " Error during initialization or mining: " + std::string (e.what ()),
97
+ false );
98
+ shutdown ();
99
+ } catch (...) {
100
+ Log::get ().error (" Unknown error during initialization or mining" , false );
101
+ shutdown ();
95
102
}
96
103
try {
97
- thread .join ();
104
+ monitor_thread .join ();
98
105
} catch (...) {
99
106
Log::get ().warn (" Error joining progress monitoring thread" );
100
107
}
0 commit comments