mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-17 07:26:41 +00:00

In one of the already existing apps that I'm testing TSan on, I really see a mutex path that is longer than 10 (but not by much, something like 11-13 actually). Let's raise this to 20 and weaken the assertion so we don't crash. Differential Revision: http://reviews.llvm.org/D20427 llvm-svn: 270319
43 lines
1.1 KiB
C
43 lines
1.1 KiB
C
// RUN: %clangxx_tsan %s -o %t
|
|
// RUN: not %run %t 5 2>&1 | FileCheck %s
|
|
// RUN: not %run %t 10 2>&1 | FileCheck %s
|
|
// RUN: not %run %t 15 2>&1 | FileCheck %s
|
|
// RUN: not %run %t 20 2>&1 | FileCheck %s
|
|
// RUN: %run %t 30 2>&1 | FileCheck %s --check-prefix=CHECK-TOO-LONG-CYCLE
|
|
|
|
#include <pthread.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
int main(int argc, char *argv[]) {
|
|
int num_mutexes = 5;
|
|
if (argc > 1) num_mutexes = atoi(argv[1]);
|
|
|
|
pthread_mutex_t m[num_mutexes];
|
|
for (int i = 0; i < num_mutexes; ++i)
|
|
pthread_mutex_init(&m[i], NULL);
|
|
|
|
for (int i = 0; i < num_mutexes - 1; ++i) {
|
|
pthread_mutex_lock(&m[i]);
|
|
pthread_mutex_lock(&m[i + 1]);
|
|
|
|
pthread_mutex_unlock(&m[i]);
|
|
pthread_mutex_unlock(&m[i + 1]);
|
|
}
|
|
|
|
pthread_mutex_lock(&m[num_mutexes - 1]);
|
|
pthread_mutex_lock(&m[0]);
|
|
|
|
pthread_mutex_unlock(&m[num_mutexes - 1]);
|
|
pthread_mutex_unlock(&m[0]);
|
|
|
|
for (int i = 0; i < num_mutexes; ++i)
|
|
pthread_mutex_destroy(&m[i]);
|
|
|
|
fprintf(stderr, "PASS\n");
|
|
}
|
|
|
|
// CHECK: ThreadSanitizer: lock-order-inversion (potential deadlock)
|
|
// CHECK-TOO-LONG-CYCLE: WARNING: too long mutex cycle found
|
|
// CHECK: PASS
|