xref: /aosp_15_r20/external/compiler-rt/test/tsan/atexit2.cc (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2*7c3d14c8STreehugger Robot 
3*7c3d14c8STreehugger Robot #include <stdio.h>
4*7c3d14c8STreehugger Robot #include <stdlib.h>
5*7c3d14c8STreehugger Robot 
6*7c3d14c8STreehugger Robot int n;
7*7c3d14c8STreehugger Robot const int N = 10000;
8*7c3d14c8STreehugger Robot 
atexit1()9*7c3d14c8STreehugger Robot static void atexit1() {
10*7c3d14c8STreehugger Robot   n++;
11*7c3d14c8STreehugger Robot }
12*7c3d14c8STreehugger Robot 
atexit0()13*7c3d14c8STreehugger Robot static void atexit0() {
14*7c3d14c8STreehugger Robot   fprintf(stderr, "run count: %d\n", n);
15*7c3d14c8STreehugger Robot }
16*7c3d14c8STreehugger Robot 
main()17*7c3d14c8STreehugger Robot int main() {
18*7c3d14c8STreehugger Robot   atexit(atexit0);
19*7c3d14c8STreehugger Robot   for (int i = 0; i < N; i++)
20*7c3d14c8STreehugger Robot     atexit(atexit1);
21*7c3d14c8STreehugger Robot }
22*7c3d14c8STreehugger Robot 
23*7c3d14c8STreehugger Robot // CHECK-NOT: FATAL: ThreadSanitizer
24*7c3d14c8STreehugger Robot // CHECK-NOT: WARNING: ThreadSanitizer
25*7c3d14c8STreehugger Robot // CHECK: run count: 10000
26*7c3d14c8STreehugger Robot 
27