1 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
3 // Fails episodically on powerpc bots:
4 // https://lab.llvm.org/buildbot/#/builders/121/builds/13391
5 // UNSUPPORTED: target=powerpc64{{.*}}
10 #include <sys/types.h>
12 // Test synchronization in signal handled within IgnoreSync region.
14 const int kSignalCount
= 500;
16 __thread
int process_signals
;
19 int ready
[kSignalCount
];
20 long long data
[kSignalCount
];
22 static void handler(int sig
) {
23 if (!__atomic_load_n(&process_signals
, __ATOMIC_RELAXED
))
25 int pos
= signals_handled
++;
26 if (pos
>= kSignalCount
)
29 __atomic_store_n(&ready
[pos
], 1, __ATOMIC_RELEASE
);
32 static void* thr(void *p
) {
33 AnnotateIgnoreSyncBegin(__FILE__
, __LINE__
);
34 __atomic_store_n(&process_signals
, 1, __ATOMIC_RELAXED
);
35 while (!__atomic_load_n(&done
, __ATOMIC_RELAXED
)) {
37 AnnotateIgnoreSyncEnd(__FILE__
, __LINE__
);
42 struct sigaction act
= {};
43 act
.sa_handler
= handler
;
44 if (sigaction(SIGPROF
, &act
, 0)) {
49 t
.it_value
.tv_sec
= 0;
50 t
.it_value
.tv_usec
= 10;
51 t
.it_interval
= t
.it_value
;
52 if (setitimer(ITIMER_PROF
, &t
, 0)) {
58 pthread_create(&th
, 0, thr
, 0);
59 for (int pos
= 0; pos
< kSignalCount
; pos
++) {
60 while (__atomic_load_n(&ready
[pos
], __ATOMIC_ACQUIRE
) == 0) {
62 if (data
[pos
] != pos
) {
63 printf("at pos %d, expect %d, got %lld\n", pos
, pos
, data
[pos
]);
67 __atomic_store_n(&done
, 1, __ATOMIC_RELAXED
);
69 fprintf(stderr
, "DONE\n");
73 // CHECK-NOT: WARNING: ThreadSanitizer: