Created
December 21, 2020 10:13
-
-
Save spetrunia/77274cf2d5848e0a7e090d622695ed4e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <pthread.h> | |
struct ST { | |
pthread_mutex_t mutex; | |
char *name; | |
}; | |
int main(int argc, char **argv) { | |
ST locks[3]; | |
for (int i=0; i < 3; ++i) { | |
pthread_mutex_init(&locks[i].mutex, NULL); | |
} | |
printf("Init done\n"); | |
// Step 1 | |
pthread_mutex_lock(&locks[0].mutex); | |
pthread_mutex_lock(&locks[1].mutex); | |
pthread_mutex_unlock(&locks[0].mutex); | |
pthread_mutex_unlock(&locks[1].mutex); | |
printf("Step 1 done\n"); | |
// Step 2 | |
pthread_mutex_lock(&locks[1].mutex); | |
pthread_mutex_lock(&locks[0].mutex); | |
pthread_mutex_unlock(&locks[1].mutex); | |
pthread_mutex_unlock(&locks[0].mutex); | |
printf("Step 2 done\n"); | |
for (int i=0; i < 3; ++i) { | |
pthread_mutex_destroy(&locks[i].mutex); | |
} | |
return 0; | |
} |
Author
spetrunia
commented
Dec 21, 2020
Compilation step:
clang++-10 -fsanitize=thread test-asan.cc
./a.out
Looks like this is a known issue in tsan: google/sanitizers#814
I also asked in the forum: https://llvm.discourse.group/t/threadsanitizer-gives-false-positive-warning-about-deadlock/2483
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment