xref: /aosp_15_r20/external/compiler-rt/test/tsan/Darwin/gcd-after.mm (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot// RUN: %clang_tsan %s -o %t -framework Foundation
2*7c3d14c8STreehugger Robot// RUN: %env_tsan_opts=ignore_interceptors_accesses=1 %run %t 2>&1 | FileCheck %s
3*7c3d14c8STreehugger Robot
4*7c3d14c8STreehugger Robot#import <Foundation/Foundation.h>
5*7c3d14c8STreehugger Robot
6*7c3d14c8STreehugger Robotlong my_global;
7*7c3d14c8STreehugger Robotlong my_global2;
8*7c3d14c8STreehugger Robot
9*7c3d14c8STreehugger Robotvoid callback(void *context) {
10*7c3d14c8STreehugger Robot  my_global2 = 42;
11*7c3d14c8STreehugger Robot
12*7c3d14c8STreehugger Robot  dispatch_async(dispatch_get_main_queue(), ^{
13*7c3d14c8STreehugger Robot    CFRunLoopStop(CFRunLoopGetMain());
14*7c3d14c8STreehugger Robot  });
15*7c3d14c8STreehugger Robot}
16*7c3d14c8STreehugger Robot
17*7c3d14c8STreehugger Robotint main(int argc, const char *argv[]) {
18*7c3d14c8STreehugger Robot  fprintf(stderr, "start\n");
19*7c3d14c8STreehugger Robot
20*7c3d14c8STreehugger Robot  my_global = 10;
21*7c3d14c8STreehugger Robot  dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
22*7c3d14c8STreehugger Robot  dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_MSEC)), q, ^{
23*7c3d14c8STreehugger Robot    my_global = 42;
24*7c3d14c8STreehugger Robot
25*7c3d14c8STreehugger Robot    dispatch_async(dispatch_get_main_queue(), ^{
26*7c3d14c8STreehugger Robot      CFRunLoopStop(CFRunLoopGetMain());
27*7c3d14c8STreehugger Robot    });
28*7c3d14c8STreehugger Robot  });
29*7c3d14c8STreehugger Robot  CFRunLoopRun();
30*7c3d14c8STreehugger Robot
31*7c3d14c8STreehugger Robot  my_global2 = 10;
32*7c3d14c8STreehugger Robot  dispatch_after_f(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_MSEC)), q, NULL, &callback);
33*7c3d14c8STreehugger Robot  CFRunLoopRun();
34*7c3d14c8STreehugger Robot
35*7c3d14c8STreehugger Robot  fprintf(stderr, "done\n");
36*7c3d14c8STreehugger Robot  return 0;
37*7c3d14c8STreehugger Robot}
38*7c3d14c8STreehugger Robot
39*7c3d14c8STreehugger Robot// CHECK: start
40*7c3d14c8STreehugger Robot// CHECK: done
41*7c3d14c8STreehugger Robot// CHECK-NOT: WARNING: ThreadSanitizer
42