]>
git.proxmox.com Git - rustc.git/blob - src/compiler-rt/test/tsan/signal_sync2.cc
1 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
12 // Test synchronization in signal handled within IgnoreSync region.
14 extern "C" void AnnotateIgnoreSyncBegin(const char *f
, int l
);
15 extern "C" void AnnotateIgnoreSyncEnd(const char *f
, int l
);
17 const int kSignalCount
= 500;
19 __thread
int process_signals
;
22 int ready
[kSignalCount
];
23 long long data
[kSignalCount
];
25 static void handler(int sig
) {
26 if (!__atomic_load_n(&process_signals
, __ATOMIC_RELAXED
))
28 int pos
= signals_handled
++;
29 if (pos
>= kSignalCount
)
32 __atomic_store_n(&ready
[pos
], 1, __ATOMIC_RELEASE
);
35 static void* thr(void *p
) {
36 AnnotateIgnoreSyncBegin(__FILE__
, __LINE__
);
37 __atomic_store_n(&process_signals
, 1, __ATOMIC_RELAXED
);
38 while (!__atomic_load_n(&done
, __ATOMIC_RELAXED
)) {
40 AnnotateIgnoreSyncEnd(__FILE__
, __LINE__
);
45 struct sigaction act
= {};
46 act
.sa_handler
= handler
;
47 if (sigaction(SIGPROF
, &act
, 0)) {
52 t
.it_value
.tv_sec
= 0;
53 t
.it_value
.tv_usec
= 10;
54 t
.it_interval
= t
.it_value
;
55 if (setitimer(ITIMER_PROF
, &t
, 0)) {
61 pthread_create(&th
, 0, thr
, 0);
62 for (int pos
= 0; pos
< kSignalCount
; pos
++) {
63 while (__atomic_load_n(&ready
[pos
], __ATOMIC_ACQUIRE
) == 0) {
65 if (data
[pos
] != pos
) {
66 printf("at pos %d, expect %d, got %lld\n", pos
, pos
, data
[pos
]);
70 __atomic_store_n(&done
, 1, __ATOMIC_RELAXED
);
72 fprintf(stderr
, "DONE\n");
76 // CHECK-NOT: WARNING: ThreadSanitizer: