1 /* Simple possible deadlock */
4 static pthread_mutex_t m1
= PTHREAD_MUTEX_INITIALIZER
;
5 static pthread_mutex_t m2
= PTHREAD_MUTEX_INITIALIZER
;
7 static void *t1(void *v
)
9 pthread_mutex_lock(&m1
);
10 pthread_mutex_lock(&m2
);
11 pthread_mutex_unlock(&m1
);
12 pthread_mutex_unlock(&m2
);
17 static void *t2(void *v
)
19 pthread_mutex_lock(&m2
);
20 pthread_mutex_lock(&m1
);
21 pthread_mutex_unlock(&m1
);
22 pthread_mutex_unlock(&m2
);
31 /* prevent spurious messages from the dynamic linker */
32 pthread_mutex_lock(&m1
);
33 pthread_mutex_unlock(&m1
);
35 pthread_create(&a
, NULL
, t1
, NULL
);
36 pthread_create(&b
, NULL
, t2
, NULL
);
38 pthread_join(a
, NULL
);
39 pthread_join(b
, NULL
);