All pastes #989675 Raw Edit

Unnamed

public c v1 · immutable
#989675 ·published 2008-04-19 16:21 UTC
rendered paste body
/**************************************************************** * Chatzidimitriou Athanasios 050064				* * Askisi 2							* * Compile : gcc -pedantic -lpthread -Wall ask2.c -o ask2	* ****************************************************************/#include <stdio.h>#include <stdlib.h>#include <pthread.h>#include <unistd.h> 	/*sleep() definition */#include <malloc.h>void *thread_function(void*);int main(void){	int 	  i, thrcount;	pthread_t *thr;	printf("Number of threads: "); scanf("%d",&thrcount);	thr = (pthread_t*)malloc(thrcount*sizeof(pthread_t));	for (i = 0; i < thrcount; i++)			pthread_create(&thr[i],NULL,thread_function,(void*)(i+1));	for (i = 0; i < thrcount; i++)		pthread_join(thr[i],NULL);	return EXIT_SUCCESS;}void *thread_function(void *arg){	int i, num;	num = (int)arg;	for (i = 1; i <= num; i++)		printf("Hello from thread %d\n",num);	sleep(num);	pthread_exit(NULL);}