1 // This test verifies that dispatch_sync() doesn't actually copy the block under TSan (without TSan, it doesn't).
3 // RUN: %clangxx_tsan %s -o %t_no_tsan -fno-sanitize=thread
4 // RUN: %clangxx_tsan %s -o %t_with_tsan
6 // RUN: %run %t_no_tsan 2>&1 | FileCheck %s
7 // RUN: %run %t_with_tsan 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
9 #include <dispatch/dispatch.h>
15 static void printCopyCount() {
16 fprintf(stderr
, "copyCount = %d\n", copyCount
);
19 MyClass(const MyClass
&obj
) { copyCount
++; };
21 fprintf(stderr
, "MyClass::foo\n");
24 int MyClass::copyCount
= 0;
26 int main(int argc
, const char* argv
[]) {
27 dispatch_queue_t q
= dispatch_queue_create("my.queue", NULL
);
29 MyClass::printCopyCount();
30 void (^block
)(void) = ^{
33 MyClass::printCopyCount();
34 dispatch_sync(q
, block
);
35 MyClass::printCopyCount();
37 fprintf(stderr
, "Done.\n");
41 // CHECK: copyCount = 0
42 // CHECK: copyCount = 1
43 // CHECK: MyClass::foo
44 // CHECK: copyCount = 1