fix thread_unix for Darwin after pthread corrections in posix package

afed3ce removed the sys/unix package and moved over to sys/posix, it has
new bindings for the pthread APIs but should have been equivalent (not).

8fb7182 used `CANCEL_ENABLE :: 0`, `CANCEL_DISABLE :: 1`, `CANCEL_DEFERRED :: 0`, `CANCEL_ASYNCHRONOUS :: 1` for Darwin, while the
correct values are `1`, `0`, `2` and `0` respectively (same mistake was made for
FreeBSD in that commit).

What this meant is that the
`pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS)` was not actually
successful, but because the error wasn't checked it was assumed it was.
It also meant `pthread_setcancelstate(PTHREAD_CANCEL_ENABLE)` would
actually be setting `PTHREAD_CANCEL_DISABLE`.

The code in this PR restores the behaviour by now actually deliberately
setting `PTHREAD_CANCEL_DISABLE` and not setting
`PTHREAD_CANCEL_ASYNCHRONOUS` which was the previous behaviour that does
actually seem to work for some reason.

(I also fixed an issue in fmt where `x` would use uppercase if it was a
pointer.)
This commit is contained in:
Laytan Laats
2024-12-01 11:54:52 +11:00
committed by flysand7
parent 96e6393614
commit c08408ea08
5 changed files with 73 additions and 7 deletions
+24
View File
@@ -75,4 +75,28 @@ main :: proc() {
fmt.println("time_t", size_of(posix.time_t), align_of(posix.time_t))
fmt.println("timespec", size_of(posix.timespec), align_of(posix.timespec))
fmt.println("clock_t", size_of(posix.clock_t), align_of(posix.clock_t))
fmt.println("PTHREAD_CANCEL_ASYNCHRONOUS", posix.PTHREAD_CANCEL_ASYNCHRONOUS)
fmt.println("PTHREAD_CANCEL_DEFERRED", posix.PTHREAD_CANCEL_DEFERRED)
fmt.println("PTHREAD_CANCEL_DISABLE", posix.PTHREAD_CANCEL_DISABLE)
fmt.println("PTHREAD_CANCEL_ENABLE", posix.PTHREAD_CANCEL_ENABLE)
fmt.printfln("PTHREAD_CANCELED %#x", posix.PTHREAD_CANCELED)
fmt.println("PTHREAD_CREATE_JOINABLE", posix.PTHREAD_CREATE_JOINABLE)
fmt.println("PTHREAD_CREATE_DETACHED", posix.PTHREAD_CREATE_DETACHED)
fmt.println("PTHREAD_EXPLICIT_SCHED", posix.PTHREAD_EXPLICIT_SCHED)
fmt.println("PTHREAD_INHERIT_SCHED", posix.PTHREAD_INHERIT_SCHED)
fmt.println("PTHREAD_PRIO_INHERIT", posix.PTHREAD_PRIO_INHERIT)
fmt.println("PTHREAD_PRIO_NONE", posix.PTHREAD_PRIO_NONE)
fmt.println("PTHREAD_PRIO_PROTECT", posix.PTHREAD_PRIO_PROTECT)
fmt.println("PTHREAD_PROCESS_SHARED", posix.PTHREAD_PROCESS_SHARED)
fmt.println("PTHREAD_PROCESS_PRIVATE", posix.PTHREAD_PROCESS_PRIVATE)
fmt.println("PTHREAD_SCOPE_PROCESS", posix.PTHREAD_SCOPE_PROCESS)
fmt.println("PTHREAD_SCOPE_SYSTEM", posix.PTHREAD_SCOPE_SYSTEM)
}