summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKuba Brecka <kuba.brecka@gmail.com>2015-11-28 12:53:57 +0000
committerKuba Brecka <kuba.brecka@gmail.com>2015-11-28 12:53:57 +0000
commit23b4c845dc68a307072cd3f82e1e28f354a097f8 (patch)
tree687d57b8d70204f41e43db1721dccd77e8f8e6b2 /test
parentac79368a80c39af6f26d96d46d391b85f4bd201b (diff)
[tsan] Add release+acquire semantics for serial dispatch queues
Serial queues need extra happens-before between individual tasks executed in the same queue. This patch adds `Acquire(queue)` before the executed task and `Release(queue)` just after it (for serial queues only). Added a test case. Differential Revision: http://reviews.llvm.org/D15011 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@254229 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/tsan/Darwin/gcd-serial-queue-norace.mm40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/tsan/Darwin/gcd-serial-queue-norace.mm b/test/tsan/Darwin/gcd-serial-queue-norace.mm
new file mode 100644
index 000000000..8f6de2769
--- /dev/null
+++ b/test/tsan/Darwin/gcd-serial-queue-norace.mm
@@ -0,0 +1,40 @@
+// RUN: %clang_tsan %s -o %t -framework Foundation
+// RUN: %run %t 2>&1
+
+#import <Foundation/Foundation.h>
+
+#import "../test.h"
+
+long global;
+
+int main() {
+ NSLog(@"Hello world.");
+ NSLog(@"addr=%p\n", &global);
+
+ dispatch_queue_t q1 = dispatch_queue_create("my.queue1", DISPATCH_QUEUE_CONCURRENT);
+ dispatch_queue_t q2 = dispatch_queue_create("my.queue2", DISPATCH_QUEUE_SERIAL);
+
+ global = 42;
+ for (int i = 0; i < 10; i++) {
+ dispatch_async(q1, ^{
+ for (int i = 0; i < 100; i++) {
+ dispatch_sync(q2, ^{
+ global++;
+ });
+ }
+ });
+ }
+
+ dispatch_barrier_async(q1, ^{
+ dispatch_sync(dispatch_get_main_queue(), ^{
+ CFRunLoopStop(CFRunLoopGetCurrent());
+ });
+ });
+
+ CFRunLoopRun();
+ NSLog(@"Done.");
+}
+
+// CHECK: Hello world.
+// CHECK: Done.
+// CHECK-NOT: WARNING: ThreadSanitizer