58 lines · plain
1// RUN: %clangxx_tsan %s -o %t -framework Foundation -fobjc-arc2// RUN: %run %t 2>&1 | FileCheck %s3 4#import <Foundation/Foundation.h>5 6@interface MyClass : NSObject {7 long field;8}9@property (nonatomic, readonly) long value;10@end11 12dispatch_group_t group;13 14@implementation MyClass15 16- (void) start {17 dispatch_queue_t q = dispatch_queue_create(NULL, NULL);18 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{19 for (int i = 0; i < 1000; i++) {20 dispatch_async(q, ^{21 @synchronized(self) {22 self->field = i;23 }24 });25 }26 });27}28 29- (long) value {30 @synchronized(self) {31 return self->field;32 }33}34 35- (void)dealloc {36 dispatch_group_leave(group);37}38 39@end40 41int main() {42 group = dispatch_group_create();43 @autoreleasepool {44 for (int j = 0; j < 100; ++j) {45 dispatch_group_enter(group);46 MyClass *obj = [[MyClass alloc] init];47 [obj start];48 long x = obj.value;49 (void)x;50 }51 }52 dispatch_group_wait(group, DISPATCH_TIME_FOREVER);53 NSLog(@"Hello world");54}55 56// CHECK: Hello world57// CHECK-NOT: WARNING: ThreadSanitizer58