Exemplo n.º 1
0
int main(){
	processSieve();
	showPrimes();
	getBoundaries();
	showPrimes();
	return 0;
}
Exemplo n.º 2
0
//------------------------------------------------------------------------------------------
// A verification of the input parameter is done. If N is lower than 2 or isn't an integer
//   program will end with a error message. Global variables are also initialized. InitiThread 
//   is created. At the end of the, primeNumbers list is sorted and then all prime numbers are
//   shown.
int main(int argc, char *argv[]) {
	pthread_t initThreadId;
	srand (time(NULL));
	arrayIndex = 0;
	N = strtol(argv[1], NULL, 10);
	if(N < 2) {
		printf("Wrong input. Input must be an integer(2 or higher).\n");
		return 0;																																																																																																																	
	}
	primeNumbersSize = ceil(1.2*(N/log(N))) +1;
	primeNumbers = (QueueElem*) malloc (sizeof(QueueElem) * primeNumbersSize);
	if(sem_init(&canTerminate, 0, 0) != 0) {
		return -1;
	}
	if(pthread_mutex_init(&primeListMut, 0) != 0) {
		return -1;
	}
	
	if(pthread_create(&initThreadId, NULL, initThreadfunc, NULL)) {
		printf("Error creating thread");
	}
	sem_wait(&canTerminate);
	qsort(primeNumbers, arrayIndex, sizeof(QueueElem), compare);
	showPrimes(primeNumbers);
	return 0;
}