[compiler-rt] r356418 - [NFC][TSan][libdispatch] Fix test for dispatch_apply[_f]
Julian Lettner via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 18 14:55:41 PDT 2019
Author: yln
Date: Mon Mar 18 14:55:41 2019
New Revision: 356418
URL: http://llvm.org/viewvc/llvm-project?rev=356418&view=rev
Log:
[NFC][TSan][libdispatch] Fix test for dispatch_apply[_f]
* Array index out of bounds: 100 iterations, but size of array is 2.
* Unmatched barrier_init (2) with barrier_wait (200)
* Number of iterations must be smaller than the available parallelism
for the queue, otherwise we deadlock (since every barrier_wait call
blocks the thread).
Scary: All of this worked reliably in gcd-apply.mm (for Darwin)
Rievewed By: kubamracek
Differential Revision: https://reviews.llvm.org/D59510
Modified:
compiler-rt/trunk/test/tsan/libdispatch/apply.c
Modified: compiler-rt/trunk/test/tsan/libdispatch/apply.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/libdispatch/apply.c?rev=356418&r1=356417&r2=356418&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/libdispatch/apply.c (original)
+++ compiler-rt/trunk/test/tsan/libdispatch/apply.c Mon Mar 18 14:55:41 2019
@@ -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
More information about the llvm-commits
mailing list