From 09dd6a62b7ef8cd3d519599ad5e0c67d000fc1fe Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Mon, 11 Apr 2022 08:40:10 +0300 Subject: [PATCH] Do not use usleep between signals resend if ThreadSanitizer Issue #236 (bdwgc). For a reason, usleep() hangs trying to acquire some TSan lock when called resend_lost_signals(). * pthread_stop_world.c [!GC_OPENBSD_UTHREADS && THREAD_SANITIZER] (GC_usleep): Use sched_yield() in a loop instead of usleep() or nanosleep(); update comment. --- pthread_stop_world.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pthread_stop_world.c b/pthread_stop_world.c index 9e146831b..281fb3528 100644 --- a/pthread_stop_world.c +++ b/pthread_stop_world.c @@ -36,8 +36,9 @@ #ifndef GC_OPENBSD_UTHREADS GC_INLINE void GC_usleep(unsigned us) { -# ifdef LINT2 - /* Workaround "waiting while holding a lock" warning. */ +# if defined(LINT2) || defined(THREAD_SANITIZER) + /* Workaround "waiting while holding a lock" static analyzer warning. */ + /* Workaround a rare hang in usleep() trying to acquire TSan Lock. */ while (us-- > 0) sched_yield(); /* pretending it takes 1us */ # elif defined(CPPCHECK) /* || _POSIX_C_SOURCE >= 199309L */