• 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
8dispatch_semaphore_t sem;
9
10long global;
11long global2;
12
13void callback(void *context) {
14  global2 = 48;
15  barrier_wait(&barrier);
16
17  dispatch_semaphore_signal(sem);
18}
19
20int main() {
21  fprintf(stderr, "Hello world.\n");
22  barrier_init(&barrier, 2);
23
24  dispatch_queue_t q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
25  dispatch_group_t g = dispatch_group_create();
26  sem = dispatch_semaphore_create(0);
27
28  dispatch_group_enter(g);
29  dispatch_async(q, ^{
30    global = 47;
31    dispatch_group_leave(g);
32    barrier_wait(&barrier);
33  });
34  dispatch_group_notify(g, q, ^{
35    global = 48;
36    barrier_wait(&barrier);
37
38    dispatch_semaphore_signal(sem);
39  });
40  dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
41
42  dispatch_group_enter(g);
43  dispatch_async(q, ^{
44    global2 = 47;
45    dispatch_group_leave(g);
46    barrier_wait(&barrier);
47  });
48  dispatch_group_notify_f(g, q, NULL, &callback);
49  dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
50
51  fprintf(stderr, "Done.\n");
52}
53
54// CHECK: Hello world.
55// CHECK-NOT: WARNING: ThreadSanitizer
56// CHECK: Done.
57