mirror of
https://github.com/eosswedenorg/antelope-keygen
synced 2026-07-04 12:03:41 +02:00
src/main.cpp: in thread_search() handle edge case where number of search results is less than number of threads.
This commit is contained in:
parent
88638d0e94
commit
56fd5eecbc
1 changed files with 19 additions and 6 deletions
19
src/main.cpp
19
src/main.cpp
|
|
@ -43,12 +43,25 @@ static int n_threads = std::thread::hardware_concurrency();
|
||||||
#define search_func thread_search
|
#define search_func thread_search
|
||||||
static void thread_search(const strlist_t& words, int n) {
|
static void thread_search(const strlist_t& words, int n) {
|
||||||
|
|
||||||
|
std::vector<std::thread> t;
|
||||||
|
int d, m;
|
||||||
|
|
||||||
|
// We can use all threads
|
||||||
|
if (n >= n_threads) {
|
||||||
|
|
||||||
// create n_threads - 1 as we use main process also.
|
// create n_threads - 1 as we use main process also.
|
||||||
std::vector<std::thread> t(n_threads - 1);
|
t.resize(n_threads - 1);
|
||||||
// divide the number of results for all threads.
|
// divide the number of results for all threads.
|
||||||
int d = n / n_threads;
|
d = n / n_threads;
|
||||||
// Also calculate the reminder (will be assigned to the main thread)
|
// Also calculate the reminder (will be assigned to the main thread)
|
||||||
int m = n % n_threads;
|
m = n % n_threads;
|
||||||
|
}
|
||||||
|
// not enough results to use all threads.
|
||||||
|
else {
|
||||||
|
t.resize(n);
|
||||||
|
d = 1;
|
||||||
|
m = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Launch threads.
|
// Launch threads.
|
||||||
for(int i = 0; i < t.size(); i++) {
|
for(int i = 0; i < t.size(); i++) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue