<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62370>62370</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
TSAN: unexpected deadlock detection.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
JackyWoo
</td>
</tr>
</table>
<pre>
### Env
```
clang -v
Ubuntu clang version 15.0.7
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/11
Candidate multilib: .;@m64
Selected multilib: .;@m64
```
### Description
1. no deadlock, but report potential deadlock
```
/ not deadlock, but report potential deadlock
void notDeadlockButReport()
{
std::mutex m1;
std::mutex m2;
// m1 => m2
std::cout << "t try to acquire m1\n";
m1.lock();
std::cout << "t got m1\n";
//std::this_thread::sleep_for(std::chrono::microseconds (2)); // wait main got m2
// code never executed
std::cout << "t try to acquire m2\n";
m2.lock();
std::cout << "t got m2\n";
m2.unlock();
m1.unlock();
// m2 => m1
std::cout << "main try to acquire m2\n";
m2.lock();
std::cout << "main got m2\n";
// code never executed
std::cout << "main try to acquire m1\n";
m1.lock();
std::cout << "main got m1\n";
m1.unlock();
m2.unlock();
}
```
2. deadlock but not report
```
void deadlockButNotReport()
{
std::mutex m1;
std::mutex m2;
std::thread t([&] {
std::cout << "t try to acquire m1\n";
m1.lock();
std::cout << "t got m1\n";
std::this_thread::sleep_for(std::chrono::milliseconds (20)); // wait main got m2
std::cout << "t try to acquire m2\n";
m2.lock();
std::cout << "t got m2\n"; // code never executed
m2.unlock();
m1.unlock();
});
std::this_thread::sleep_for(std::chrono::milliseconds(10)); // wait t got m1
std::cout << "main try to acquire m2\n";
m2.lock();
std::cout << "main got m2\n";
std::cout << "main try to acquire m1\n";
m1.lock();
std::cout << "main got m1\n"; // code never executed
m1.unlock();
m2.unlock();
t.join();
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0l8mO2zgQhp-GuhAWpNJi9UEHL9Fg5pDDJIM5BjRZbTOhSA8Xx_32A0mO3GlvcacbEGRbrOVnsfiJZs7JtUasSTEnxTJiwW-Mrf9i_NvTv8ZEKyOeagLZcNEPekeSJUlmh3uZHK7-J1dMr-nkYPLPKmgf6PBwh9ZJo2laxEk8HQw-M7tGT7IZ3VfllzKfbPlESR32k7UOB5ONRSZoawSqznBrnNwPQ39q55lSKJbSdkMEmuAsgWYl9WDRmKAF5UwLKZhH-sdiQeXgxbw0-sQLmjgm0Ci5ItCsOSfQHJQdZUGTJu8bPn3X8A9D9E-okHsUb616Meptg_Ky88pmNCbZnORJW-Yvsl8zetFch_vYikt03Mptr_mZQRpTbahAJpTh3wgs6Cp4anFrrKdb41F7ydTR4GwqaKg2_t4oOyNF57c8PJ0H_3fvQaAicCg8mc6HL9R5QbIZyWZt8LinbdrNfxii9GQUxtGjDYGmk9qmlGRLkn3orE4DcBM8JdmCZAtKADz19ol6Qxn_L0iLXeJioQnAT_nbNB6m3ks_q-wk8Nr4M9Fe6h39_Ua6L77f4cMDpxC3Xx6NJVAds2ys0eZQC8mtcciNFo4SqKDT1sv7UYvvTHraMqkHMXChZNwIpBp3aCnukQeP4jWVg7OVg1dW7iTaTzGDvhC1Tc-PnfYJjH2S3hbVF_F3Jnw18K0J31ynu2Tf0-G3ZV_p8EtrcXEByXR5hXYQj4jpAdRBaYDQWaceQOJIn4_mKoDOUOZ-Bj3bzf2rus9VzAmUpFjSMdnR4Q3YdJ1Pv8eoF3O6n1BKyeeESu5G1Bsg6DqG7kPRza14kvYiqa7ukG4nnKXXG60GgSq9sBhjV1zK_Do03v8i-CU0vh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