]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - tools/lib/lockdep/tests/ABBA_2threads.c
Merge remote-tracking branches 'asoc/topic/ac97', 'asoc/topic/ac97-mfd', 'asoc/topic...
[mirror_ubuntu-focal-kernel.git] / tools / lib / lockdep / tests / ABBA_2threads.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
11a1ac20
AAF
2#include <stdio.h>
3#include <pthread.h>
4
5pthread_mutex_t a = PTHREAD_MUTEX_INITIALIZER;
6pthread_mutex_t b = PTHREAD_MUTEX_INITIALIZER;
7pthread_barrier_t bar;
8
9void *ba_lock(void *arg)
10{
11 int ret, i;
12
13 pthread_mutex_lock(&b);
14
15 if (pthread_barrier_wait(&bar) == PTHREAD_BARRIER_SERIAL_THREAD)
16 pthread_barrier_destroy(&bar);
17
18 pthread_mutex_lock(&a);
19
20 pthread_mutex_unlock(&a);
21 pthread_mutex_unlock(&b);
22}
23
24int main(void)
25{
26 pthread_t t;
27
28 pthread_barrier_init(&bar, NULL, 2);
29
30 if (pthread_create(&t, NULL, ba_lock, NULL)) {
31 fprintf(stderr, "pthread_create() failed\n");
32 return 1;
33 }
34 pthread_mutex_lock(&a);
35
36 if (pthread_barrier_wait(&bar) == PTHREAD_BARRIER_SERIAL_THREAD)
37 pthread_barrier_destroy(&bar);
38
39 pthread_mutex_lock(&b);
40
41 pthread_mutex_unlock(&b);
42 pthread_mutex_unlock(&a);
43
44 pthread_join(t, NULL);
45
46 return 0;
47}