24 lines
538 B
C
24 lines
538 B
C
#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");
|
|
} |