Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add more Mc Mini tests
[simgrid.git] / teshsuite / mc / mcmini / simple_semaphore_deadlock.c
1 #include <pthread.h>
2 #include <semaphore.h>
3
4 sem_t sem1;
5 sem_t sem2;
6 pthread_t thread1, thread2;
7
8 static void * thread_doit1(void *forks_arg) {
9     sem_wait(&sem2);
10     sem_wait(&sem1);
11     sem_post(&sem1);
12     sem_post(&sem2);
13     return NULL;
14 }
15
16 static void * thread_doit2(void *forks_arg) {
17     sem_wait(&sem1);
18     sem_wait(&sem2);
19     sem_post(&sem2);
20     sem_post(&sem1);
21     return NULL;
22 }
23
24 int main(int argc, char* argv[]) {
25     sem_init(&sem1, 0, 1);
26     sem_init(&sem2, 0, 1);
27
28     pthread_create(&thread1, NULL, &thread_doit1, NULL);
29     pthread_create(&thread2, NULL, &thread_doit2, NULL);
30
31     pthread_join(thread1, NULL);
32     pthread_join(thread2, NULL);
33
34     return 0;
35 }
36