• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// RUN: %clang_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
6#import "../test.h"
7
8long global;
9long array[2];
10
11void callback(void *context, size_t i) {
12  long n = global;
13  array[i] = n + i;
14  barrier_wait(&barrier);
15}
16
17int main(int argc, const char *argv[]) {
18  barrier_init(&barrier, 2);
19  fprintf(stderr, "start\n");
20  dispatch_queue_t q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
21
22  global = 42;
23
24  dispatch_apply(100, q, ^(size_t i) {
25    long n = global;
26    array[i] = n + i;
27    barrier_wait(&barrier);
28  });
29
30  for (int i = 0; i < 100; i++) {
31    fprintf(stderr, "array[%d] = %ld\n", i, array[i]);
32  }
33
34  global = 43;
35
36  dispatch_apply_f(100, q, NULL, &callback);
37
38  fprintf(stderr, "done\n");
39  return 0;
40}
41
42// CHECK: start
43// CHECK: done
44// CHECK-NOT: WARNING: ThreadSanitizer
45