• 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
6void notify_callback(void *context) {
7  // Do nothing.
8}
9
10int main() {
11  NSLog(@"Hello world.");
12
13  dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
14
15  for (int i = 0; i < 300000; i++) {
16    dispatch_group_t g = dispatch_group_create();
17    dispatch_group_enter(g);
18    dispatch_async(q, ^{
19      dispatch_group_leave(g);
20    });
21    dispatch_group_notify(g, q, ^{
22      // Do nothing.
23    });
24    dispatch_release(g);
25  }
26
27  for (int i = 0; i < 300000; i++) {
28    dispatch_group_t g = dispatch_group_create();
29    dispatch_group_enter(g);
30    dispatch_async(q, ^{
31      dispatch_group_leave(g);
32    });
33    dispatch_group_notify_f(g, q, NULL, &notify_callback);
34    dispatch_release(g);
35  }
36
37  NSLog(@"Done.");
38}
39
40// CHECK: Hello world.
41// CHECK: Done.
42// CHECK-NOT: WARNING: ThreadSanitizer
43// CHECK-NOT: CHECK failed
44