コード例 #1
0
void TorrentTrackerCommManager::requestPeers(const uint64_t amountUploaded, 
												const uint64_t amountDownloaded, 
												const uint64_t amountLeft) {

	std::vector<future_t *> futures;

	std::vector<TorrentTrackerComm *>::iterator it;
	for (it = trackers.begin(); it != trackers.end(); ++it) {

		//spawn thread to requestPeers in each tracker
		//if return null, re-establish connection
		CallRequestPeersParams * param = new CallRequestPeersParams();
		param->amountUploaded = amountUploaded;
		param->amountDownloaded = amountDownloaded;
		param->amountLeft = amountLeft;
		param->tracker = *it;
		param->trackers = &trackers;
		param->peerList = &peerList;

		future_t * f = thread_pool_submit(threadPool, (thread_pool_callable_func_t) &callRequestPeers, param);
		futures.push_back(f);
	}

	//Finish and delete all running threads
	std::vector<future_t *>::iterator futureIt;
	for (futureIt = futures.begin(); futureIt != futures.end(); futureIt++) {

		future_get(*futureIt);
		future_free(*futureIt);
	}
}
コード例 #2
0
ファイル: test.c プロジェクト: saintaadvark/Search
// Code needs modification, copied from main function where
// I used it as an inline test
void random_string_multithread_lookup()
{

	graph agraph;
	int i, nline, nacro, c=0;
	vertex** vert;
	char acro[100], meaning[100], chbang;
	FILE *fp;
	thread_pool* tpcb;
	future* qfuture;	
	argstruct *args;
	
	while (1) {
		scanf("%s",acro);
		args = (argstruct*)malloc(sizeof(argstruct));
		args->acronym = (char*)malloc(strlen(acro));
		strcpy(args->acronym, acro); 
		printf("%s\n",args->acronym);
		thread_pool_submit(tpcb, SearchFileWrapper, (void*)args);

		acro[c] ++;
		if (acro[c] > 'Z'){
			acro[c] = 'A';
			c++;
			if (c>2)
				while(1);
		}
	}
}
コード例 #3
0
ファイル: threadpool_test.c プロジェクト: dsengar/threadpool
static int
run_test(int nthreads)
{
    struct benchmark_data * bdata = start_benchmark();
    struct thread_pool * threadpool = thread_pool_new(nthreads);
   
    struct arg2 args = {
        .a = 20,
        .b = 22,
    };

    struct future * sum = thread_pool_submit(threadpool, (fork_join_task_t) adder_task, &args);

    uintptr_t ssum = (uintptr_t) future_get(sum);
    future_free(sum);
    thread_pool_shutdown_and_destroy(threadpool);

    stop_benchmark(bdata);

    // consistency check
    if (ssum != 42) {
        fprintf(stderr, "Wrong result, expected 42, got %ld\n", ssum);
        abort();
    }

    report_benchmark_results(bdata);
    printf("Test successful.\n");
    free(bdata);
    return 0;
}

/**********************************************************************************/

static void
usage(char *av0, int exvalue)
{
    fprintf(stderr, "Usage: %s [-n <n>]\n"
                    " -n number of threads in pool, default %d\n"
                    , av0, DEFAULT_THREADS);
    exit(exvalue);
}