• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// RUN: %clangxx_tsan %s -o %t -framework Foundation
2// RUN: %env_tsan_opts=ignore_interceptors_accesses=1 %run %t 2>&1 | FileCheck %s
3
4#import <Foundation/Foundation.h>
5
6int main() {
7  fprintf(stderr, "start\n");
8
9  dispatch_queue_t background_q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
10  dispatch_queue_t main_q = dispatch_get_main_queue();
11
12  dispatch_async(background_q, ^{
13    __block long block_var = 0;
14
15    dispatch_sync(main_q, ^{
16      block_var = 42;
17    });
18
19    fprintf(stderr, "block_var = %ld\n", block_var);
20
21    dispatch_sync(dispatch_get_main_queue(), ^{
22      CFRunLoopStop(CFRunLoopGetCurrent());
23    });
24  });
25
26  CFRunLoopRun();
27  fprintf(stderr, "done\n");
28}
29
30// CHECK: start
31// CHECK: block_var = 42
32// CHECK: done
33// CHECK-NOT: WARNING: ThreadSanitizer
34// CHECK-NOT: CHECK failed
35