aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaytan <laytanlaats@hotmail.com>2025-11-13 21:21:18 +0100
committerGitHub <noreply@github.com>2025-11-13 21:21:18 +0100
commit4bfcc5ca5fcaa9690f1c04b355a86f18f311387f (patch)
treeb60d8d3589ec7d7515d2ba98c9c36b2aba2e25e6
parentc4262ccc77618f81742a9fef7991ca08553d3733 (diff)
parent71afb8e7a5bd62cc0f601857d079edc5420c8147 (diff)
Merge pull request #5900 from laytan/another-thread-cancel-try
removes the darwin specific paths from thread_unix
-rw-r--r--core/thread/thread_unix.odin23
1 files changed, 8 insertions, 15 deletions
diff --git a/core/thread/thread_unix.odin b/core/thread/thread_unix.odin
index 1db32657e..e18ea593d 100644
--- a/core/thread/thread_unix.odin
+++ b/core/thread/thread_unix.odin
@@ -22,11 +22,6 @@ _create :: proc(procedure: Thread_Proc, priority: Thread_Priority) -> ^Thread {
__unix_thread_entry_proc :: proc "c" (t: rawptr) -> rawptr {
t := (^Thread)(t)
- // We need to give the thread a moment to start up before we enable cancellation.
- // NOTE(laytan): setting to .DISABLE on darwin, with .ENABLE pthread_cancel would deadlock
- // most of the time, don't ask me why.
- can_set_thread_cancel_state := posix.pthread_setcancelstate(.DISABLE when ODIN_OS == .Darwin else .ENABLE, nil) == nil
-
t.id = sync.current_thread_id()
for (.Started not_in sync.atomic_load(&t.flags)) {
@@ -34,16 +29,14 @@ _create :: proc(procedure: Thread_Proc, priority: Thread_Priority) -> ^Thread {
}
// Enable thread's cancelability.
- // NOTE(laytan): Darwin does not correctly/fully support all of this, not doing this does
- // actually make pthread_cancel work in the capacity of my tests, while executing this would
- // basically always make it deadlock.
- if ODIN_OS != .Darwin && can_set_thread_cancel_state {
- err := posix.pthread_setcancelstate(.ENABLE, nil)
- assert_contextless(err == nil)
-
- err = posix.pthread_setcanceltype(.ASYNCHRONOUS, nil)
- assert_contextless(err == nil)
- }
+ err := posix.pthread_setcancelstate(.ENABLE, nil)
+ assert_contextless(err == nil)
+
+ // NOTE(laytan): .ASYNCHRONOUS should make `pthread_cancel` cancel immediately
+ // instead of waiting for a cancellation point.
+ // This does not seem to work on at least Darwin and NetBSD though.
+ err = posix.pthread_setcanceltype(.ASYNCHRONOUS, nil)
+ assert_contextless(err == nil)
{
init_context := t.init_context