Browse Source

Crawler thread should know amount of threads for correct sleep

pull/1/head
Roman Mindalev 11 years ago
parent
commit
69a942b4e9
  1. 7
      main.cpp

7
main.cpp

@ -11,8 +11,6 @@ @@ -11,8 +11,6 @@
#include "bitcoin.h"
#include "db.h"
#define NTHREADS 24
using namespace std;
bool fTestNet = false;
@ -126,6 +124,7 @@ extern "C" { @@ -126,6 +124,7 @@ extern "C" {
CAddrDb db;
extern "C" void* ThreadCrawler(void* data) {
int *nThreads=(int*)data;
do {
std::vector<CServiceResult> ips;
int wait = 5;
@ -133,7 +132,7 @@ extern "C" void* ThreadCrawler(void* data) { @@ -133,7 +132,7 @@ extern "C" void* ThreadCrawler(void* data) {
int64 now = time(NULL);
if (ips.empty()) {
wait *= 1000;
wait += rand() % (500 * NTHREADS);
wait += rand() % (500 * *nThreads);
Sleep(wait);
continue;
}
@ -422,7 +421,7 @@ int main(int argc, char **argv) { @@ -422,7 +421,7 @@ int main(int argc, char **argv) {
pthread_attr_setstacksize(&attr_crawler, 0x20000);
for (int i=0; i<opts.nThreads; i++) {
pthread_t thread;
pthread_create(&thread, &attr_crawler, ThreadCrawler, NULL);
pthread_create(&thread, &attr_crawler, ThreadCrawler, &opts.nThreads);
}
pthread_attr_destroy(&attr_crawler);
printf("done\n");

Loading…
Cancel
Save