@@ -68,6 +68,7 @@ void mineParallel(const Settings& settings,
6868 num_instances = Setup::getMaxInstances ();
6969 }
7070 const bool has_miner_profile = settings.miner_profile .empty ();
71+ const bool restart_miners = (settings.num_mine_hours <= 0 );
7172
7273 // prepare instance settings
7374 auto instance_settings = settings;
@@ -79,22 +80,34 @@ void mineParallel(const Settings& settings,
7980 AdaptiveScheduler cpuhours_scheduler (3600 ); // 1 hour (fixed!!)
8081 ApiClient api_client;
8182
82- // run miner processes and monitor them
8383 Log::get ().info (" Starting parallel mining using " +
84- std::to_string (num_instances) + " miner instances" );
85- while (true ) {
86- // check if miner processes are alive
84+ std::to_string (num_instances) + " instances" );
85+ const auto start_time = std::chrono::steady_clock::now ();
86+
87+ // run miner processes and monitor them
88+ bool finished = false ;
89+ while (!finished) {
90+ // check if miner processes are alive, restart them if should not stop
91+ finished = true ;
8792 for (size_t i = 0 ; i < children_pids.size (); i++) {
88- if (!isChildProcessAlive (children_pids[i])) {
93+ const auto pid = children_pids[i];
94+ if (pid != 0 && isChildProcessAlive (pid)) {
95+ // still alive
96+ finished = false ;
97+ } else if (pid == 0 || restart_miners) {
98+ // restart process
8999 if (has_miner_profile) {
90100 instance_settings.miner_profile = std::to_string (i);
91101 }
92102 children_pids[i] = fork (instance_settings, args);
93103 std::this_thread::sleep_for (std::chrono::seconds (5 ));
104+ finished = false ;
94105 }
95106 }
107+
96108 // wait some time
97109 std::this_thread::sleep_for (std::chrono::seconds (10 ));
110+
98111 // report CPU hours
99112 if (cpuhours_scheduler.isTargetReached ()) {
100113 cpuhours_scheduler.reset ();
@@ -106,6 +119,14 @@ void mineParallel(const Settings& settings,
106119 }
107120 }
108121 }
122+
123+ // finished log message
124+ auto cur_time = std::chrono::steady_clock::now ();
125+ int64_t mins =
126+ std::chrono::duration_cast<std::chrono::minutes>(cur_time - start_time)
127+ .count ();
128+ Log::get ().info (" Finished parallel mining after " + std::to_string (mins) +
129+ " minutes" );
109130}
110131
111132int dispatch (Settings settings, const std::vector<std::string>& args) {
0 commit comments