aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFeoramund <161657516+Feoramund@users.noreply.github.com>2024-06-02 21:25:04 -0400
committerFeoramund <161657516+Feoramund@users.noreply.github.com>2024-06-02 21:27:36 -0400
commit7764ab2ab0a45786d3c27c2a5bfad264e181b7b7 (patch)
tree71dfe4c3533729657966e911dbc0090d2907ba7a
parent6a5633df2d3c7a398d6aa20e1024f6f380c9d987 (diff)
Prevent test runner deadlock on NetBSD
Add `pthread_testcancel` to `core:sys/unix`
-rw-r--r--core/sys/unix/pthread_unix.odin1
-rw-r--r--core/testing/signal_handler_libc.odin13
2 files changed, 14 insertions, 0 deletions
diff --git a/core/sys/unix/pthread_unix.odin b/core/sys/unix/pthread_unix.odin
index 5760560ee..c876a214a 100644
--- a/core/sys/unix/pthread_unix.odin
+++ b/core/sys/unix/pthread_unix.odin
@@ -116,4 +116,5 @@ foreign pthread {
pthread_mutexattr_setpshared :: proc(attrs: ^pthread_mutexattr_t, value: c.int) -> c.int ---
pthread_mutexattr_getpshared :: proc(attrs: ^pthread_mutexattr_t, result: ^c.int) -> c.int ---
+ pthread_testcancel :: proc () ---
}
diff --git a/core/testing/signal_handler_libc.odin b/core/testing/signal_handler_libc.odin
index ff3dbe135..f60cf2540 100644
--- a/core/testing/signal_handler_libc.odin
+++ b/core/testing/signal_handler_libc.odin
@@ -6,6 +6,7 @@ import "base:intrinsics"
import "core:c/libc"
import "core:encoding/ansi"
import "core:sync"
+@require import "core:sys/unix"
@(private="file") stop_runner_flag: libc.sig_atomic_t
@@ -75,6 +76,18 @@ This is a dire bug and should be reported to the Odin developers.
// Idle until this thread is terminated by the runner,
// otherwise we may continue to generate signals.
intrinsics.cpu_relax()
+
+ when ODIN_OS != .Windows {
+ // NOTE(Feoramund): Some UNIX-like platforms may require this.
+ //
+ // During testing, I found that NetBSD 10.0 refused to
+ // terminate a task thread, even when its thread had been
+ // properly set to PTHREAD_CANCEL_ASYNCHRONOUS.
+ //
+ // The runner would stall after returning from `pthread_cancel`.
+
+ unix.pthread_testcancel()
+ }
}
}
}