brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.0 KiB · 18369fd Raw
44 lines · plain
1// RUN: %clang_tsan %s -o %t -framework Foundation2// RUN: %deflake %run %t 2>&1 | FileCheck %s3 4#import <Foundation/Foundation.h>5 6#import "../test.h"7 8long global;9 10int main() {11  fprintf(stderr, "Hello world.\n");12  print_address("addr=", 1, &global);13  barrier_init(&barrier, 2);14 15  global = 42;16  dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{17    global = 43;18    barrier_wait(&barrier);19  });20 21  dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{22    barrier_wait(&barrier);23    global = 44;24 25    dispatch_sync(dispatch_get_main_queue(), ^{26      CFRunLoopStop(CFRunLoopGetCurrent());27    });28  });29 30  CFRunLoopRun();31  fprintf(stderr, "Done.\n");32}33 34// CHECK: Hello world.35// CHECK: WARNING: ThreadSanitizer: data race36// CHECK: Write of size 837// CHECK: Previous write of size 838// CHECK: Location is global39// CHECK: Thread {{.*}} is a GCD worker thread40// CHECK-NOT: failed to restore the stack41// CHECK: Thread {{.*}} is a GCD worker thread42// CHECK-NOT: failed to restore the stack43// CHECK: Done.44