71 Commits

Author SHA1 Message Date
Laytan Laats
71afb8e7a5 removes the darwin specific paths from thread_unix
I know I left a note there about deadlocks but it doesn't seem to happen
anymore, especially now that the test runner creates cancellation points.

Also, what was this `can_set_thread_cancel_state` for? It does not make
sense to me that it enables cancellation, and then does it again later.
With the comment it seems like it should be `.DISABLE` to first disable
and then wait for the thread to start. But even that seems weird, why
do you need to do that? I removed it.
2025-11-07 21:40:25 +01:00
Laytan Laats
25389ed086 thread: set stack size to rlimit 2025-08-02 15:22:23 +02:00
Jeroen van Rijn
1903d7211e Fix early join after start. 2025-06-21 11:47:00 +02:00
Jeroen van Rijn
5aa377e64e Revert changes to thread_unix.odin 2025-06-12 16:36:40 +02:00
Jeroen van Rijn
59ba37f232 Remove transmute 2025-06-12 16:05:34 +02:00
Jeroen van Rijn
994b5a2a6c Remove c import 2025-06-12 16:01:31 +02:00
Jeroen van Rijn
caf41aa046 Fix #5321 2025-06-12 16:00:24 +02:00
Laytan Laats
cc3c9bd871 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.)
2024-10-30 15:51:56 +01:00
Laytan
afed3ce6b5 remove pthread from sys/unix and use sys/posix where used 2024-10-28 19:20:43 +01:00
Karl Zylinski
093ade0504 Merge branch 'master' into file-tags-without-comments 2024-09-17 19:36:17 +02:00
Karl Zylinski
19f0127e55 Moved all packages in core, base, vendor, tests and examples to use new #+ file tag syntax. 2024-09-14 18:27:49 +02:00
Feoramund
4d14b4257e Convert POSIX Thread to use semaphore instead
One less value to store, and it should be less of a hack too.

Semaphores will not wait around if they have the go-ahead; they depend
on an internal value being non-zero, instead of whatever was loaded when
they started waiting, which is the case with a `Cond`.
2024-09-09 16:19:14 -04:00
Feoramund
74b28f1ff9 Fix rare double-join possibility in POSIX thread._join
This was occuring about 1/100 times with the test runner's thread pool.
2024-09-09 16:19:14 -04:00
Laytan Laats
1e6419b5b7 fix zombie thread leak in thread self cleanup 2024-08-28 16:22:38 +02:00
Feoramund
d338642dc4 Add API for freeing thread_local state 2024-08-26 06:01:59 -04:00
Laytan Laats
28fac62a02 fix some bugs with -disable-assert 2024-07-16 18:44:18 +02:00
Laytan Laats
604551eb2d wasi: make the demo run on wasi and run it in CI 2024-06-29 23:15:31 +02:00
Feoramund
0ea0fac2f9 Call pthread_cancel on Darwin, with advisory comment 2024-06-28 20:47:37 -04:00
Laytan Laats
00dfff7ee0 core/thread: fix a deadlock situation on unix 2024-06-07 20:28:09 +02:00
gingerBill
f9fd8f0c25 Merge pull request #3439 from andreas-jonsson/netbsd
NetBSD support
2024-05-15 10:33:52 +01:00
Feoramund
33c6f75a2e Fix joining non-Started threads from blocking main thread 2024-05-10 17:24:45 -04:00
Andreas T Jonsson
b72c2edabb Merge branch 'master' into netbsd 2024-05-10 09:04:52 +02:00
Feoramund
9cdb7b2584 Fix discrepancy with pthread cancelability state 2024-04-22 17:16:33 -04:00
Andreas T Jonsson
41d4dfbcd5 Fixed concurrency issue
Fixed broken thread policy causing deadlocks.
2024-04-18 16:20:49 +02:00
Andreas T Jonsson
38640d5d9e Updated core lib and did cleanup
Updated core with some path related functions and did some minor code cleanup.
Most of the standard library function is just a matter of copy what is there for the other BSDs.
2024-04-18 10:12:42 +02:00
Andreas T Jonsson
4558f3992a Initial commit of NetBSD port 2024-04-16 14:27:29 +02:00
avanspector
fca691a066 fix core:thread and a memory leak
in the future probably native non-pthread implementation for haiku will be required
2024-02-27 02:38:06 +01:00
gingerBill
3e7e779abf Replace core:* to base:* where appropriate 2024-01-28 22:18:51 +00:00
gingerBill
2cc22d118d Require parentheses for #align(N) 2023-08-15 14:55:02 +01:00
hikari
3b8515beb0 [core:thread] Seeing if this fixes network tests 2023-06-07 20:52:41 +03:00
hikari
7b62b81ebd [core:thread] Fix compilation 2023-06-07 20:03:19 +03:00
hikari
dcf4e51787 [core:thread] Added self_cleanup flag to properly auto-clean threads 2023-06-07 19:11:16 +03:00
Tetralux
5d6b923244 [thread] Refactor handling of 'init_context' + add doc comments for it 2023-06-03 08:08:18 +00:00
Jeroen van Rijn
f4ad4c7aa6 Disable thread.terminate on Darwin for now. 2022-05-11 16:17:35 +02:00
Jeroen van Rijn
8fb718245a Implement pthread_cancel. 2022-05-11 15:52:04 +02:00
Jeroen van Rijn
56e3b7cb7d Fix join on *nix. 2022-05-11 13:43:29 +02:00
gingerBill
4eb4ae6305 Replace sync with sync2 2022-03-30 17:42:44 +01:00
Dale Weiler
3da8fa9b27 can use sync.guard here 2022-03-11 08:41:03 -05:00
Dale Weiler
32ba5e7ad2 formatting 2022-03-11 08:36:04 -05:00
Dale Weiler
52df80dccd fix for mac & use atomic store on write side to avoid race 2022-03-11 08:35:23 -05:00
Dale Weiler
7f845bb165 fix for spurious wakeups 2022-03-11 08:30:03 -05:00
Dale Weiler
0e6de5673b fix thread data races 2022-03-11 08:06:23 -05:00
Sébastien Marie
5676c9e7eb initial OpenBSD support 2022-02-25 08:49:25 +00:00
powerc9000
2f3c5336d9 Fix mutex and conditions trying to be destroyed twice in unix 2022-01-27 15:38:16 -07:00
gingerBill
d165de0d4d Move thread initialization variables in thread_unix.odin 2021-10-26 11:46:31 +01:00
gingerBill
c9e6862332 Add id to thread.Thread 2021-10-24 12:30:25 +01:00
gingerBill
ca33cb990b Strip semicolons in core which were missing 2021-09-08 13:12:38 +01:00
gingerBill
21cbac755e Make or_else and or_return operators (binary and suffix respectively) 2021-08-15 17:14:35 +01:00
gingerBill
f7413ca974 Fix thread_unix.odin 2021-07-05 16:36:07 +01:00
gingerBill
9b3a0251ca Use or_else in the core library when it makes sense 2021-07-05 16:33:01 +01:00