[compiler-rt] [llvm] [tsan] Introduce Adaptive Delay Scheduling to TSAN (PR #178836)

Chris Cotter via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 14 22:44:02 PST 2026


================
@@ -1371,20 +1383,23 @@ INTERCEPTOR(int, pthread_cond_signal, void *c) {
   void *cond = init_cond(c);
   SCOPED_TSAN_INTERCEPTOR(pthread_cond_signal, cond);
   MemoryAccessRange(thr, pc, (uptr)c, sizeof(uptr), false);
+  GetFuzzingScheduler().MutexCvOp();
   return REAL(pthread_cond_signal)(cond);
 }
 
 INTERCEPTOR(int, pthread_cond_broadcast, void *c) {
   void *cond = init_cond(c);
   SCOPED_TSAN_INTERCEPTOR(pthread_cond_broadcast, cond);
   MemoryAccessRange(thr, pc, (uptr)c, sizeof(uptr), false);
+  GetFuzzingScheduler().MutexCvOp();
   return REAL(pthread_cond_broadcast)(cond);
 }
 
 INTERCEPTOR(int, pthread_cond_destroy, void *c) {
   void *cond = init_cond(c);
   SCOPED_TSAN_INTERCEPTOR(pthread_cond_destroy, cond);
   MemoryAccessRange(thr, pc, (uptr)c, sizeof(uptr), true);
+  GetFuzzingScheduler().MutexCvOp();
----------------
ccotter wrote:

My latest changes have given a holistic update to when delays are injected into the posix interceptors, mostly limiting the scope to those involving clear "happens before" relationships (and documenting in the class docs, but I've not yet updated any user-facing docs).

I had an intuition that delaying in other places like pthread_cond_signal may help in situations like in https://ceur-ws.org/Vol-2344/paper9.pdf "Data race on variable a," where two threads sync on one particular edge, but end up hiding another unsynchronized access. I can't articulate or demonstrate this for delays other than those in atomic sync ops or mutex happens-before ops, so let's remove it now. If we can demonstrate the need later, we can revisit.

The "Data race on variable a" scenario does highlight that TSAN can miss races that TSAN itself *could have observed*, but is not able to observe due to the actual interleavings. TSAN can only see what it sees (per OS scheduling), so the delays intend to help TSAN see more.

https://github.com/llvm/llvm-project/pull/178836


More information about the llvm-commits mailing list