Skip to content

Real-time Sanitizer causes pthread_cond_signal to segfault when a thread is doing a timed wait on a condition variable #146120

Open
@adrew0809

Description

@adrew0809

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

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions