CS3413/Assignment3/examples/4-passing_data_wrongly.c

21 lines
576 B
C
Raw Permalink Normal View History

2023-10-08 23:19:49 -03:00
#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");
}