1 // RUN: %clang_tsan %s -o %t -framework Foundation
2 // RUN: %deflake %run %t 2>&1 | FileCheck %s
4 #import <Foundation/Foundation.h>
8 @interface MyClass : NSObject {
9 long instance_variable;
11 - (void)method:(long)value;
14 @implementation MyClass
16 - (void)method:(long)value {
17 self->instance_variable = value;
23 NSLog(@"Hello world.");
24 barrier_init(&barrier, 2);
26 MyClass *my_object = [MyClass new];
27 [my_object method:42];
29 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
30 [my_object method:43];
31 barrier_wait(&barrier);
34 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
35 barrier_wait(&barrier);
36 [my_object method:44];
38 dispatch_sync(dispatch_get_main_queue(), ^{
39 CFRunLoopStop(CFRunLoopGetCurrent());
48 // CHECK: Hello world.
49 // CHECK: WARNING: ThreadSanitizer: data race
50 // CHECK: Write of size 8
51 // CHECK: #0 -[MyClass method:]
52 // CHECK: Previous write of size 8
53 // CHECK: #0 -[MyClass method:]
54 // CHECK: Location is heap block