1 // SPDX-License-Identifier: GPL-2.0
5 pthread_mutex_t a
= PTHREAD_MUTEX_INITIALIZER
;
6 pthread_mutex_t b
= PTHREAD_MUTEX_INITIALIZER
;
9 void *ba_lock(void *arg
)
13 pthread_mutex_lock(&b
);
15 if (pthread_barrier_wait(&bar
) == PTHREAD_BARRIER_SERIAL_THREAD
)
16 pthread_barrier_destroy(&bar
);
18 pthread_mutex_lock(&a
);
20 pthread_mutex_unlock(&a
);
21 pthread_mutex_unlock(&b
);
28 pthread_barrier_init(&bar
, NULL
, 2);
30 if (pthread_create(&t
, NULL
, ba_lock
, NULL
)) {
31 fprintf(stderr
, "pthread_create() failed\n");
34 pthread_mutex_lock(&a
);
36 if (pthread_barrier_wait(&bar
) == PTHREAD_BARRIER_SERIAL_THREAD
)
37 pthread_barrier_destroy(&bar
);
39 pthread_mutex_lock(&b
);
41 pthread_mutex_unlock(&b
);
42 pthread_mutex_unlock(&a
);
44 pthread_join(t
, NULL
);