summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--compiler-rt/test/tsan/libdispatch/apply.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/compiler-rt/test/tsan/libdispatch/apply.c b/compiler-rt/test/tsan/libdispatch/apply.c
index d5c991f3204..d361169eed0 100644
--- a/compiler-rt/test/tsan/libdispatch/apply.c
+++ b/compiler-rt/test/tsan/libdispatch/apply.c
@@ -1,16 +1,13 @@
// RUN: %clang_tsan %s -o %t
-// RUN: %run %t 2>&1 | FileCheck %s
-
-// TODO(yln): Deadlocks while gcd-apply.mm does not. What's the difference
-// between C and Obj-C compiler?
-// REQUIRES: disable
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
#include <dispatch/dispatch.h>
#include "../test.h"
+const size_t size = 2;
long global;
-long array[2];
+long array[size];
void callback(void *context, size_t i) {
long n = global;
@@ -19,7 +16,6 @@ void callback(void *context, size_t i) {
}
int main(int argc, const char *argv[]) {
- barrier_init(&barrier, 2);
fprintf(stderr, "start\n");
// Warm up GCD (workaround for macOS Sierra where dispatch_apply might run single-threaded).
@@ -29,24 +25,34 @@ int main(int argc, const char *argv[]) {
global = 42;
- dispatch_apply(100, q, ^(size_t i) {
+ barrier_init(&barrier, size);
+ dispatch_apply(size, q, ^(size_t i) {
long n = global;
array[i] = n + i;
barrier_wait(&barrier);
});
- for (int i = 0; i < 100; i++) {
- fprintf(stderr, "array[%d] = %ld\n", i, array[i]);
+ for (size_t i = 0; i < size; i++) {
+ fprintf(stderr, "array[%ld] = %ld\n", i, array[i]);
}
- global = 43;
+ global = 142;
+
+ barrier_init(&barrier, size);
+ dispatch_apply_f(size, q, NULL, &callback);
- dispatch_apply_f(100, q, NULL, &callback);
+ for (size_t i = 0; i < size; i++) {
+ fprintf(stderr, "array[%ld] = %ld\n", i, array[i]);
+ }
fprintf(stderr, "done\n");
return 0;
}
// CHECK: start
+// CHECK: array[0] = 42
+// CHECK: array[1] = 43
+// CHECK: array[0] = 142
+// CHECK: array[1] = 143
// CHECK: done
// CHECK-NOT: WARNING: ThreadSanitizer
OpenPOWER on IntegriCloud