Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Easy Sonar smells.
[simgrid.git] / examples / sthread / pthread-mutex-simple.c
1 /* Simple test code with no bug  */
2
3 #include <pthread.h>
4 #include <stdio.h>
5
6 pthread_mutex_t mutex;
7
8 static void* thread1_fun(void* ignore)
9 {
10   pthread_mutex_lock(&mutex);
11   pthread_mutex_unlock(&mutex);
12
13   return NULL;
14 }
15 static void* thread2_fun(void* ignore)
16 {
17   pthread_mutex_lock(&mutex);
18   pthread_mutex_unlock(&mutex);
19
20   return NULL;
21 }
22
23 int main(int argc, char* argv[])
24 {
25   fprintf(stderr, "User main is starting\n");
26
27   pthread_mutex_init(&mutex, NULL);
28
29   pthread_t thread1;
30   pthread_t thread2;
31   pthread_create(&thread1, NULL, thread1_fun, NULL);
32   fprintf(stderr, "here\n");
33   pthread_create(&thread2, NULL, thread2_fun, NULL);
34   fprintf(stderr, "there\n");
35   pthread_join(thread1, NULL);
36   pthread_join(thread2, NULL);
37
38   fprintf(stderr, "User main is done\n");
39   return 0;
40 }