Linux and Solaris 11 offer pthread_sigqueue(3) that is to sigqueue(2) what pthread_kill(3) is to kill(2). I've been using pthread_sigqueue() on my own software to offer different "cancellation paths". To illustrate my need, here is the piece of the code that I want to be cancellable: https://gitlab.com/emilua/emilua/-/blob/v0.7.1/src/file.cpp#L520-532 As you can see, I use setjmp() for a switch expression that will allow me to jump to different cancel-handling paths. Here's the cancellation type-1: https://gitlab.com/emilua/emilua/-/blob/v0.7.1/src/file.cpp#L463 Here's cancellation type-2: https://gitlab.com/emilua/emilua/-/blob/v0.7.1/src/file.cpp#L93 Both cancellators just use pthread_sigqueue(). Cancellator type-1 will use sigval::sival_int=1 and cancellator type-2 will use sigval::sival_int=2. The sighandler (SA_SIGINFO) will use this value as an argument to longjmp(): https://gitlab.com/emilua/emilua/-/blob/v0.7.1/src/core.cpp#L756 Can FreeBSD have pthread_sigqueue() as in Linux and Solaris?
https://reviews.freebsd.org/D44867
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=220aa0f450409948b869237e5c4505f992c913ce commit 220aa0f450409948b869237e5c4505f992c913ce Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2024-04-19 14:40:40 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2024-04-23 16:51:22 +0000 libthr: add pthread_sigqueue(3) PR: 278459 Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D44867 include/pthread.h | 7 +++ lib/libthr/pthread.map | 4 ++ lib/libthr/thread/Makefile.inc | 1 + lib/libthr/thread/thr_private.h | 1 + lib/libthr/thread/thr_sigqueue.c (new) | 79 ++++++++++++++++++++++++++++++++++ 5 files changed, 92 insertions(+)
A commit in branch stable/14 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=e449481bee5fd08d4342156696eb4a6eef531ef0 commit e449481bee5fd08d4342156696eb4a6eef531ef0 Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2024-04-19 14:40:40 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2024-04-30 00:48:09 +0000 libthr: add pthread_sigqueue(3) PR: 278459 (cherry picked from commit 220aa0f450409948b869237e5c4505f992c913ce) include/pthread.h | 7 +++ lib/libthr/pthread.map | 4 ++ lib/libthr/thread/Makefile.inc | 1 + lib/libthr/thread/thr_private.h | 1 + lib/libthr/thread/thr_sigqueue.c (new) | 79 ++++++++++++++++++++++++++++++++++ 5 files changed, 92 insertions(+)