CS3413/Lab3/examples/4-passing_data_wrongly.c
2023-10-04 18:07:09 -03:00

21 lines
576 B
C

#include<pthread.h>
#include<stdio.h>
void* run (void* arg){
int i = (int) arg;
printf("Hello from run, arg is %i\n",i);
}
int main(){
pthread_t thread[10];
int i = 0;
for (i = 0 ; i < 10; ++i)
pthread_create(&thread, NULL, &run,(void*)i);
// Notice how warnings are generated. This can be resolved by properly
// allocating space for the thread parameters.
// Note, that if you are using stack variable, the values might be corrupted
for (i = 0 ; i < 10; i++){
pthread_join(thread[i],NULL);
}
printf("In main");
}