]> git.proxmox.com Git - rustc.git/blob - src/compiler-rt/test/tsan/mmap_stress.cc
Imported Upstream version 1.6.0+dfsg1
[rustc.git] / src / compiler-rt / test / tsan / mmap_stress.cc
1 // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2 #include "test.h"
3 #include <errno.h>
4 #include <sys/mman.h>
5
6 void *SubWorker(void *arg) {
7 (void)arg;
8 const int kMmapSize = 65536;
9 for (int i = 0; i < 500; i++) {
10 int *ptr = (int*)mmap(0, kMmapSize, PROT_READ | PROT_WRITE,
11 MAP_PRIVATE | MAP_ANON, -1, 0);
12 *ptr = 42;
13 munmap(ptr, kMmapSize);
14 }
15 return 0;
16 }
17
18 void *Worker1(void *arg) {
19 (void)arg;
20 pthread_t th[4];
21 for (int i = 0; i < 4; i++)
22 pthread_create(&th[i], 0, SubWorker, 0);
23 for (int i = 0; i < 4; i++)
24 pthread_join(th[i], 0);
25 return 0;
26 }
27
28 void *Worker(void *arg) {
29 (void)arg;
30 pthread_t th[4];
31 for (int i = 0; i < 4; i++)
32 pthread_create(&th[i], 0, Worker1, 0);
33 for (int i = 0; i < 4; i++)
34 pthread_join(th[i], 0);
35 return 0;
36 }
37
38 int main() {
39 pthread_t th[4];
40 for (int i = 0; i < 4; i++)
41 pthread_create(&th[i], 0, Worker, 0);
42 for (int i = 0; i < 4; i++)
43 pthread_join(th[i], 0);
44 fprintf(stderr, "DONE\n");
45 }
46
47 // CHECK: DONE