// RUN: %clang_tsan %s -o %t -framework Foundation
// RUN: %run %t 2>&1

#import <Foundation/Foundation.h>

void notify_callback(void *context) {
  // Do nothing.
}

int main() {
  NSLog(@"Hello world.");

  dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
  
  for (int i = 0; i < 300000; i++) {
    dispatch_group_t g = dispatch_group_create();
    dispatch_group_enter(g);
    dispatch_async(q, ^{
      dispatch_group_leave(g);
    });
    dispatch_group_notify(g, q, ^{
      // Do nothing.
    });
    dispatch_release(g);
  }

  for (int i = 0; i < 300000; i++) {
    dispatch_group_t g = dispatch_group_create();
    dispatch_group_enter(g);
    dispatch_async(q, ^{
      dispatch_group_leave(g);
    });
    dispatch_group_notify_f(g, q, nullptr, &notify_callback);
    dispatch_release(g);
  }

  NSLog(@"Done.");
}

// CHECK: Hello world.
// CHECK: Done.
// CHECK-NOT: WARNING: ThreadSanitizer
// CHECK-NOT: CHECK failed

// RUN: %clang_tsan %s -o %t -framework Foundation
// RUN: %run %t 2>&1

#import <Foundation/Foundation.h>

void notify_callback(void *context) {
  // Do nothing.
}

int main() {
  NSLog(@"Hello world.");

  dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
  
  for (int i = 0; i < 300000; i++) {
    dispatch_group_t g = dispatch_group_create();
    dispatch_group_enter(g);
    dispatch_async(q, ^{
      dispatch_group_leave(g);
    });
    dispatch_group_notify(g, q, ^{
      // Do nothing.
    });
    dispatch_release(g);
  }

  for (int i = 0; i < 300000; i++) {
    dispatch_group_t g = dispatch_group_create();
    dispatch_group_enter(g);
    dispatch_async(q, ^{
      dispatch_group_leave(g);
    });
    dispatch_group_notify_f(g, q, NULL, &notify_callback);
    dispatch_release(g);
  }

  NSLog(@"Done.");
}

// CHECK: Hello world.
// CHECK: Done.
// CHECK-NOT: WARNING: ThreadSanitizer
// CHECK-NOT: CHECK failed

Change nullptr to NULL in one Darwin test.
[tsan] Change nullptr to NULL in one Darwin test.

Depending on the version of libcxx, nullptr might not be available. Let's use NULL instead.



git-svn-id: c199f293c43da69278bea8e88f92242bf3aa95f7@264058 91177308-0d34-0410-b5e6-96231b3b80d8
