diff options
Diffstat (limited to 'src/randomx_pow.cpp')
| -rw-r--r-- | src/randomx_pow.cpp | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/src/randomx_pow.cpp b/src/randomx_pow.cpp index 4454fd1..a509543 100644 --- a/src/randomx_pow.cpp +++ b/src/randomx_pow.cpp | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | #include <thread> | 8 | #include <thread> |
| 9 | #include <vector> | 9 | #include <vector> |
| 10 | #include <mutex> | 10 | #include <mutex> |
| 11 | #include <system_error> | ||
| 11 | 12 | ||
| 12 | // Fixed key (seed) that determines the RandomX cache/dataset. Keeping it | 13 | // Fixed key (seed) that determines the RandomX cache/dataset. Keeping it |
| 13 | // constant avoids per-epoch "reseed" logic; for the CPU+RAM fairness goal | 14 | // constant avoids per-epoch "reseed" logic; for the CPU+RAM fairness goal |
| @@ -183,13 +184,28 @@ bool RandomXInitDataset(int nThreads) | |||
| 183 | 184 | ||
| 184 | std::vector<std::thread> workers; | 185 | std::vector<std::thread> workers; |
| 185 | unsigned long per = total / nThreads; | 186 | unsigned long per = total / nThreads; |
| 186 | for (int i = 0; i < nThreads; i++) | 187 | try |
| 187 | { | 188 | { |
| 188 | unsigned long start = i * per; | 189 | for (int i = 0; i < nThreads; i++) |
| 189 | unsigned long count = (i == nThreads - 1) ? (total - start) : per; | 190 | { |
| 190 | workers.emplace_back([start, count]() { | 191 | unsigned long start = i * per; |
| 191 | randomx_init_dataset(g_dataset, g_cache, start, count); | 192 | unsigned long count = (i == nThreads - 1) ? (total - start) : per; |
| 192 | }); | 193 | workers.emplace_back([start, count]() { |
| 194 | randomx_init_dataset(g_dataset, g_cache, start, count); | ||
| 195 | }); | ||
| 196 | } | ||
| 197 | } | ||
| 198 | catch (const std::system_error& e) | ||
| 199 | { | ||
| 200 | // Same refusal as the allocation failure above: light mode is slow | ||
| 201 | // but alive, std::terminate is neither. Join the workers that did | ||
| 202 | // start before releasing the dataset out from under them. | ||
| 203 | for (auto& w : workers) w.join(); | ||
| 204 | randomx_release_dataset(g_dataset); | ||
| 205 | g_dataset = NULL; | ||
| 206 | printf("RandomX: cannot spawn dataset init threads (%s), staying in light mode\n", | ||
| 207 | e.what()); | ||
| 208 | return false; | ||
| 193 | } | 209 | } |
| 194 | for (auto& w : workers) w.join(); | 210 | for (auto& w : workers) w.join(); |
| 195 | 211 | ||