예제 #1
0
파일: ll_tests_0.c 프로젝트: zfogg/libll
void LL_find_test(int count) {
    nodePtr head     = newTestLL(count),
            indexedN = LL_ofIndex(head, LL_length(head) / 2);

    LL_value_t indexedNValue = LL_findByValue(head, indexedN->value)->value;

    processTestResults("find: value in list",
            indexedNValue == indexedN->value);
    LL_free(&head, &indexedN);

    processTestResults("find: value not in list",
            LL_find(head, indexedN) == NULL);
    LL_freeAll(&head);
}
예제 #2
0
char *test_linked_list_free()
{
    LL_free(head);

    return NULL;
}
예제 #3
0
파일: primes.c 프로젝트: FoXPeeD/OS-bwis
int main(int argc, char **argv) {
	setvbuf(stdout, NULL, _IONBF, 0);
	setvbuf(stderr, NULL, _IONBF, 0);

	pthread_mutex_t total_threads_lock;
	pthread_mutex_init(&(total_threads_lock), NULL);
	int total_threads = 1;

	if (argc != 3) {
		printf("Please give 2 arguments\n");
		return -1;
	}

	int N = atoi(argv[1]);
	int T = atoi(argv[2]);

	if (N < 2 || T < 1) {
		printf("Invalid arguments\n");
		return -1;
	}

	// Init
	LL_getRangeFrom2(N);

	FILE *f = fopen("thread-1.log", "w");
	if (f == NULL) {
		printf("Error opening file!\n");
		return 1;
	}

	FILE* firstf = f;
	int i;
	Thread_info* arg_threads = (Thread_info*) malloc(
			sizeof(Thread_info) * (T - 1));
	for (i = 2; i <= T; i++) {
		char fname[260];
		sprintf(fname, "thread-%d.log", i);
		f = fopen(fname, "w");
		if (f == NULL) {
			printf("Error opening file!\n");
			return 1;
		}
		arg_threads[i - 2].f = f;
		arg_threads[i - 2].i = i;
		arg_threads[i - 2].N = N;
	}
	int j = 0;
	pthread_t pthread;
	pthread_t pthreads[T];
	for (j = 0; j < T - 1; j++) {
		pthread_create(&pthread, NULL, thread_do, &(arg_threads[j]));
		pthreads[j] = pthread;
	}

	f = firstf;
	i = 1;

	Node p = handleCandidate(LL_head(), f, i);

	while (p && p->num * p->num <= N) {
		p = handleCandidate(p, f, i);
	}

	if (p) {
		release(p->prev);
		release(p);
	}

	fclose(f);

	for (j = 0; j < T - 1; j++)
		pthread_join(pthreads[j], NULL);

	f = fopen("primes.log", "w");
	if (f == NULL) {
		printf("Error opening file!\n");
		return 1;
	}

	LL_logAll(f);
	fclose(f);
	LL_free();


	free(arg_threads);

	return 0;
}