1 // RUN: %clangxx -pthread %s -o %t
4 // FIXME: Crashes on some bots in pthread_exit.
5 // RUN: %run %t %if tsan %{ 0 %} %else %{ 1 %}
17 static void *fn(void *args
) {
19 auto ret
= (void *)(~(uintptr_t)args
);
25 int main(int argc
, char **argv
) {
26 use_exit
= atoi(argv
[1]);
28 assert(!pthread_create(&thread
[0], nullptr, fn
, (void *)1000));
29 assert(!pthread_create(&thread
[1], nullptr, fn
, (void *)1001));
30 assert(!pthread_create(&thread
[2], nullptr, fn
, (void *)1002));
31 assert(!pthread_create(&thread
[3], nullptr, fn
, (void *)1003));
33 assert(!pthread_attr_init(&attr
));
34 assert(!pthread_attr_setdetachstate(&attr
, PTHREAD_CREATE_DETACHED
));
35 assert(!pthread_create(&thread
[4], &attr
, fn
, (void *)1004));
36 assert(!pthread_attr_destroy(&attr
));
38 assert(!pthread_detach(thread
[0]));
42 while (pthread_tryjoin_np(thread
[1], &res
))
44 assert(~(uintptr_t)res
== 1001);
50 while (pthread_timedjoin_np(thread
[2], &res
, &tm
))
52 assert(~(uintptr_t)res
== 1002);
57 assert(!pthread_join(thread
[3], &res
));
58 assert(~(uintptr_t)res
== 1003);