Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
c0f48f68c55fb25a1bd5cbaddb5031a4baf60e44
[simgrid.git] / examples / sthread / sthread-mutex-simple.c
1 /* Simple test code with no bug  */
2
3 #include "src/sthread/sthread.h"
4 #include <stdio.h>
5
6 sthread_mutex_t mutex;
7
8 static void* thread_fun(void* ignore)
9 {
10   sthread_mutex_lock(&mutex);
11   sthread_mutex_unlock(&mutex);
12
13   return NULL;
14 }
15
16 int main(int argc, char* argv[])
17 {
18   sthread_mutex_init(&mutex, NULL);
19
20   sthread_t thread1;
21   sthread_t thread2;
22   sthread_create(&thread1, NULL, thread_fun, NULL);
23   sthread_create(&thread2, NULL, thread_fun, NULL);
24   sthread_join(thread1, NULL);
25   sthread_join(thread2, NULL);
26
27   sthread_mutex_destroy(&mutex);
28
29   fprintf(stderr, "done\n");
30   return 0;
31 }