brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · 82fcc4e Raw
56 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 8@interface MyClass : NSObject {9  long instance_variable;10}11- (void)method:(long)value;12@end13 14@implementation MyClass15 16- (void)method:(long)value {17  self->instance_variable = value;18}19 20@end21 22int main() {23  NSLog(@"Hello world.");24  barrier_init(&barrier, 2);25  26  MyClass *my_object = [MyClass new];27  [my_object method:42];28  29  dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{30    [my_object method:43];31    barrier_wait(&barrier);32  });33  34  dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{35    barrier_wait(&barrier);36    [my_object method:44];37 38    dispatch_sync(dispatch_get_main_queue(), ^{39      CFRunLoopStop(CFRunLoopGetCurrent());40    });41  });42  43  CFRunLoopRun();44  NSLog(@"Done.");45  return 0;46}47 48// CHECK: Hello world.49// CHECK: WARNING: ThreadSanitizer: data race50// CHECK:   Write of size 851// CHECK:     #0 -[MyClass method:]52// CHECK:   Previous write of size 853// CHECK:     #0 -[MyClass method:]54// CHECK:   Location is heap block55// CHECK: Done.56