1// RUN: %clangxx_tsan %s -o %t -framework Foundation -std=c++11 2// RUN: %run %t 2>&1 | FileCheck %s 3 4#import <Foundation/Foundation.h> 5#import <libkern/OSAtomic.h> 6 7#include <thread> 8 9#include "../test.h" 10 11typedef struct { 12 void *next; 13 long data; 14} ListItem; 15 16OSQueueHead q; 17 18int main(int argc, const char *argv[]) { 19 barrier_init(&barrier, 2); 20 21 std::thread t1([] { 22 ListItem *li = new ListItem{nullptr, 42}; 23 OSAtomicEnqueue(&q, li, 0); 24 barrier_wait(&barrier); 25 }); 26 27 std::thread t2([] { 28 barrier_wait(&barrier); 29 ListItem *li = (ListItem *)OSAtomicDequeue(&q, 0); 30 fprintf(stderr, "data = %ld\n", li->data); 31 }); 32 33 t1.join(); 34 t2.join(); 35 36 fprintf(stderr, "done\n"); 37 38 return 0; 39} 40 41// CHECK: data = 42 42// CHECK: done 43// CHECK-NOT: WARNING: ThreadSanitizer 44