1 // RUN: %clangxx_msan -std=c++11 -O0 %s -o %t && %run %t
2 // The main goal is getting the pthread name back and
3 // FreeBSD based do not support this feature
4 // UNSUPPORTED: android, target={{.*freebsd.*}}
6 // Regression test for a deadlock in pthread_getattr_np
11 #include <sanitizer/msan_interface.h>
15 // Stall child thread on this lock to make sure it doesn't finish
16 // before the end of the pthread_getname_np() / pthread_setname_np() tests.
17 static pthread_mutex_t lock
;
19 void *ThreadFn(void *) {
20 pthread_mutex_lock (&lock
);
21 pthread_mutex_unlock (&lock
);
28 pthread_mutex_init (&lock
, NULL
);
29 pthread_mutex_lock (&lock
);
31 int res
= pthread_create(&t
, 0, ThreadFn
, 0);
34 const char *kMyThreadName
= "my-thread-name";
35 #if defined(__NetBSD__)
36 res
= pthread_setname_np(t
, "%s", (void *)kMyThreadName
);
38 res
= pthread_setname_np(t
, kMyThreadName
);
43 res
= pthread_getname_np(t
, buf
, sizeof(buf
));
45 assert(strcmp(buf
, kMyThreadName
) == 0);
47 pthread_mutex_unlock (&lock
);
49 res
= pthread_join(t
, 0);