1 // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2 // This test is flaky on several builders:
3 // https://groups.google.com/d/msg/llvm-dev/KUFPdLhBN3Q/L75rwW9xBgAJ
4 // The cause is unknown (lit hides test output on failures).
5 // Let's try to re-enable it at least in one configutaion.
6 // REQUIRES: linux, x86_64-target-arch
11 void *SubWorker(void *arg
) {
13 const int kMmapSize
= 65536;
14 for (int i
= 0; i
< 500; i
++) {
15 int *ptr
= (int*)mmap(0, kMmapSize
, PROT_READ
| PROT_WRITE
,
16 MAP_PRIVATE
| MAP_ANON
, -1, 0);
17 if (ptr
== MAP_FAILED
)
18 exit(printf("mmap failed: %d\n", errno
));
20 if (munmap(ptr
, kMmapSize
))
21 exit(printf("munmap failed: %d\n", errno
));
26 void *Worker1(void *arg
) {
29 for (int i
= 0; i
< 4; i
++) {
30 if (pthread_create(&th
[i
], 0, SubWorker
, 0))
31 exit(printf("pthread_create failed: %d\n", errno
));
33 for (int i
= 0; i
< 4; i
++) {
34 if (pthread_join(th
[i
], 0))
35 exit(printf("pthread_join failed: %d\n", errno
));
40 void *Worker(void *arg
) {
43 for (int i
= 0; i
< 4; i
++) {
44 if (pthread_create(&th
[i
], 0, Worker1
, 0))
45 exit(printf("pthread_create failed: %d\n", errno
));
47 for (int i
= 0; i
< 4; i
++) {
48 if (pthread_join(th
[i
], 0))
49 exit(printf("pthread_join failed: %d\n", errno
));
56 for (int i
= 0; i
< 4; i
++) {
57 if (pthread_create(&th
[i
], 0, Worker
, 0))
58 exit(printf("pthread_create failed: %d\n", errno
));
60 for (int i
= 0; i
< 4; i
++) {
61 if (pthread_join(th
[i
], 0))
62 exit(printf("pthread_join failed: %d\n", errno
));
64 fprintf(stderr
, "DONE\n");