<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/146120>146120</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Real-time Sanitizer causes pthread_cond_signal to segfaul when a thread is doing a timed wait on a condition variable
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
adrew0809
</td>
</tr>
</table>
<pre>
A simple std::condition_variable usage leads to segfault when building with clang 20, -fsanitizer=realtime.
Nothing is annotated as non-blocking.
```
#include <condition_variable>
#include <future>
#include <mutex>
#include <thread>
int main() {
std::mutex mut;
std::condition_variable cv;
bool go{false};
const auto fut = std::async(std::launch::async, [&] {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
{
std::unique_lock<std::mutex> lock(mut);
go = true;
}
cv.notify_one();
});
std::unique_lock<std::mutex> lock(mut);
// normal wait is fine
// cv.wait(lock, [&] { return go; });
// but timed wait segfaults
cv.wait_for(lock, std::chrono::milliseconds(200), [&] { return go; });
}
```
```
(gdb) r
Starting program: /app/iplatform/rsan_bug_build/rsan_bug
warning: Error disabling address space randomization: Operation not permitted
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7f05071ff640 (LWP 254606)]
Thread 2 "rsan_bug" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7f05071ff640 (LWP 254606)]
0x00007f0507c85233 in pthread_cond_signal () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) bt
#0 0x00007f0507c85233 in pthread_cond_signal () from /lib/x86_64-linux-gnu/libc.so.6
#1 0x000058e1f2851b92 in main::$_0::operator()() const ()
```
If the condition_variable is not yet waited on, there is no segfault. If it is not a timed wait, there is no segfault.
[CMakeLists.txt](https://github.com/user-attachments/files/20952913/CMakeLists.txt)
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/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