From 61818395312c6e765dc8e7be8bf32cd2c82fec39 Mon Sep 17 00:00:00 2001 From: nagachika Date: Sun, 13 Nov 2022 11:18:27 +0900 Subject: merge revision(s) eacedcfe44a0ae22bf54ddb7df193c48d4c857c6: [Backport #19105] mutex: Raise a ThreadError when detecting a fiber deadlock (#6680) [Bug #19105] If no fiber scheduler is registered and the fiber that owns the lock and the one that try to acquire it both belong to the same thread, we're in a deadlock case. Co-authored-by: Jean Boussier --- test/fiber/test_mutex.rb | 22 +++++++++++++++++++++- thread_sync.c | 4 ++++ 2 files changed, 25 insertions(+), 1 deletion(-) --- thread_sync.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'thread_sync.c') diff --git a/thread_sync.c b/thread_sync.c index eaf2c025b9..27b617c907 100644 --- a/thread_sync.c +++ b/thread_sync.c @@ -311,6 +311,10 @@ do_mutex_lock(VALUE self, int interruptible_p) } } else { + if (!th->vm->thread_ignore_deadlock && rb_fiber_threadptr(mutex->fiber) == th) { + rb_raise(rb_eThreadError, "deadlock; lock already owned by another fiber belonging to the same thread"); + } + enum rb_thread_status prev_status = th->status; rb_hrtime_t *timeout = 0; rb_hrtime_t rel = rb_msec2hrtime(100); -- cgit v1.2.3