[Bug 283101] pthread_cancel() doesn't cancel a thread that's currently in pause()

From: <bugzilla-noreply_at_freebsd.org>
Date: Sat, 21 Dec 2024 18:43:20 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=283101

--- Comment #19 from Konstantin Belousov <kib@FreeBSD.org> ---
(In reply to vedad from comment #18)
Hm, no, this case is not interesting: there is THR_LOCK() call in the thread
exit path, and the debugging patch was too rough to avoid this case.  When
the victim exiting, the deadlock cannot occur, since we are already past
the pause()/sigsuspend() sleep.

I slightly improved the detector part of the patch.  Also, it is available
at https://kib.kiev.ua/git/deviant3.git branch cancel.  Lets try again.

diff --git a/lib/libthr/thread/thr_sig.c b/lib/libthr/thread/thr_sig.c
index b953c430158c..a393e51b746a 100644
--- a/lib/libthr/thread/thr_sig.c
+++ b/lib/libthr/thread/thr_sig.c
@@ -191,8 +191,15 @@ sigcancel_handler(int sig __unused,
        struct pthread *curthread = _get_curthread();
        int err;

-       if (THR_IN_CRITICAL(curthread))
+       if (THR_IN_CRITICAL(curthread)) {
+               if (!curthread->cancelling) {
+                       void *p[1];
+                       
+                       p[0] = curthread;
+                       abort2("thr_in_critical %p", 1, p);
+               }
                return;
+       }
        err = errno;
        check_suspend(curthread);
        check_cancel(curthread, ucp);

-- 
You are receiving this mail because:
You are the assignee for the bug.