1// RUN: %clangxx_msan -fsanitize-memory-track-origins -O0 %s -o %t && %run %t
2
3// Regression test for a deadlock in pthread_getattr_np
4
5#include <assert.h>
6#include <pthread.h>
7#if defined(__FreeBSD__)
8#include <pthread_np.h>
9#endif
10
11void *ThreadFn(void *) {
12 pthread_attr_t attr;
13#if defined(__FreeBSD__)
14 // On FreeBSD it needs to allocate attr underlying memory
15 int res = pthread_attr_init(&attr);
16 assert(!res);
17 res = pthread_attr_get_np(pthread_self(), &attr);
18#else
19 int res = pthread_getattr_np(th: pthread_self(), attr: &attr);
20#endif
21 assert(!res);
22 return 0;
23}
24
25int main(void) {
26 pthread_t t;
27 int res = pthread_create(newthread: &t, attr: 0, start_routine: ThreadFn, arg: 0);
28 assert(!res);
29 res = pthread_join(th: t, thread_return: 0);
30 assert(!res);
31 return 0;
32}
33

source code of compiler-rt/test/msan/pthread_getattr_np_deadlock.cpp