Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add a TESH for the new sthread feature
[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   fprintf(stderr, "The first thread is terminating.\n");
14   return NULL;
15 }
16 static void* thread2_fun(void* ignore)
17 {
18   pthread_mutex_lock(&mutex);
19   pthread_mutex_unlock(&mutex);
20
21   fprintf(stderr, "The second thread is terminating.\n");
22   return NULL;
23 }
24
25 int main(int argc, char* argv[])
26 {
27   pthread_mutex_init(&mutex, NULL);
28
29   pthread_t thread1, thread2;
30   pthread_create(&thread1, NULL, thread1_fun, NULL);
31   pthread_create(&thread2, NULL, thread2_fun, NULL);
32   fprintf(stderr, "All threads are started.\n");
33   pthread_join(thread1, NULL);
34   pthread_join(thread2, NULL);
35
36   fprintf(stderr, "User's main is terminating.\n");
37   return 0;
38 }