CS3413/Assignment3/examples/3-losing_track_of_threads-fixed.c

24 lines
538 B
C
Raw Normal View History

2023-10-08 23:19:49 -03:00
#include<pthread.h>
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<time.h>
#include<sys/time.h>
void* run (void* arg){
sleep(10-(int)arg);
printf("Hello from run\n");
}
int main(){
pthread_t thread[10];
int i = 0;
for (i = 0 ; i < 10; ++i)
pthread_create(&thread[i], NULL, &run,(void*)i);
// If you plan to use the results of all the threads, consider
// using join for all of the threads
for (i = 0 ; i < 10; ++i)
pthread_join(thread[i],NULL);
printf("In main");
}