I wrote this brief example in order to understand thread programming in C.It was supposed to write "thread 0". But there is no output. Here is the code.
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
int i=0;
pthread_mutex_t mutex;
void * fonction(){
pthread_mutex_lock(&mutex);
printf("thread %d
",i++);
pthread_mutex_unlock(&mutex);
pthread_exit(NULL);
}
int main(){
pthread_t a;
pthread_mutex_init(&mutex,NULL);
pthread_create(&a,NULL,fonction,NULL);
return EXIT_SUCCESS;
}
Can someone help me ? Ps : I used this to compile it
gcc -pthread test.c -o test
See Question&Answers more detail:os