[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / compiler-rt / test / sanitizer_common / TestCases / Linux / pthread_join.cpp
blob212a28dd3985bbee8e78cfebc75d7aa91f375b1b
1 // RUN: %clangxx -pthread %s -o %t
2 // RUN: %run %t 0
4 // FIXME: Crashes on some bots in pthread_exit.
5 // RUN: %run %t %if tsan %{ 0 %} %else %{ 1 %}
7 // REQUIRES: glibc
9 #include <assert.h>
10 #include <ctime>
11 #include <pthread.h>
12 #include <stdint.h>
13 #include <stdlib.h>
14 #include <unistd.h>
16 bool use_exit;
17 static void *fn(void *args) {
18 sleep(1);
19 auto ret = (void *)(~(uintptr_t)args);
20 if (use_exit)
21 pthread_exit(ret);
22 return ret;
25 int main(int argc, char **argv) {
26 use_exit = atoi(argv[1]);
27 pthread_t thread[5];
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));
32 pthread_attr_t attr;
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]));
41 void *res;
42 while (pthread_tryjoin_np(thread[1], &res))
43 sleep(1);
44 assert(~(uintptr_t)res == 1001);
48 void *res;
49 timespec tm = {0, 1};
50 while (pthread_timedjoin_np(thread[2], &res, &tm))
51 sleep(1);
52 assert(~(uintptr_t)res == 1002);
56 void *res;
57 assert(!pthread_join(thread[3], &res));
58 assert(~(uintptr_t)res == 1003);
61 return 0;