1 // RUN: %clangxx_tsan %s -o %t -framework Foundation -std=c++11
2 // RUN: %run %t 2>&1 | FileCheck %s
4 #import <Foundation/Foundation.h>
5 #import <libkern/OSAtomic.h>
7 int main(int argc, const char *argv[]) {
9 bool ret = OSAtomicTestAndClear(7, &value);
10 fprintf(stderr, "value = %d, ret = %d\n", value, ret);
11 // CHECK: value = 0, ret = 1
13 ret = OSAtomicTestAndSet(4, &value);
14 fprintf(stderr, "value = %d, ret = %d\n", value, ret);
15 // CHECK: value = 8, ret = 0
17 ret = OSAtomicTestAndClear(4, &value);
18 fprintf(stderr, "value = %d, ret = %d\n", value, ret);
19 // CHECK: value = 0, ret = 1
21 ret = OSAtomicTestAndSet(12, &value);
22 fprintf(stderr, "value = %d, ret = %d\n", value, ret);
23 // CHECK: value = 2048, ret = 0
25 ret = OSAtomicTestAndSet(13, &value);
26 fprintf(stderr, "value = %d, ret = %d\n", value, ret);
27 // CHECK: value = 3072, ret = 0
29 ret = OSAtomicTestAndClear(12, &value);
30 fprintf(stderr, "value = %d, ret = %d\n", value, ret);
31 // CHECK: value = 1024, ret = 1