Commit Graph

123 Commits

Author SHA1 Message Date
Jeroen van Rijn 07c59cb4db Early out and propagate nil in create*
If allocation of a `^Thread` failed, `create*` now properly return `nil`,
so you can assert on that instead of calling `thread.destroy` on a null pointer, say.
2025-04-17 17:26:24 +02:00
Jeroen van Rijn 1c655b84e4 Fix #5049
Keep in mind that `thread.create` needs an allocator to be set, as it returns `^Thread`.
2025-04-17 16:53:07 +02:00
Waqar Ahmed 8a27042d24 Use a proper Queue in thread.Pool
With lots of tasks the dynamic array takes a big performance hit as its
allocating all the time on pop_front
2024-11-30 22:29:47 +05: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 c3f363cfbc Fix data race when pool_stop_task is called 2024-09-09 16:19:15 -04:00
Feoramund 45da009377 Use more atomic handling of thread flags
This can prevent a data race on Linux with `Self_Cleanup`.
2024-09-09 16:19:15 -04: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
pkova 5b9b21e756 Fix thread sanitizer errors surfaced by tests/core/io 2024-09-03 16:30:51 +03:00
Laytan Laats 1e6419b5b7 fix zombie thread leak in thread self cleanup 2024-08-28 16:22:38 +02:00
gingerBill 91f8c626bb Merge pull request #4148 from Feoramund/tls-cleaner
Add API for freeing `thread_local` state
2024-08-26 22:37:08 +01:00
Feoramund 9fac03b84c Fix use-after-free in thread.Pool 2024-08-26 06:39:05 -04:00
Feoramund d338642dc4 Add API for freeing thread_local state 2024-08-26 06:01:59 -04:00
flysand7 b84b4c47d7 [thread]: Document all functions in core:thread 2024-07-21 14:34:36 +11: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
Feoramund 9dcf345795 Set thread pool is_running to false on shutdown 2024-06-02 14:54:32 -04:00
Feoramund 21064fbb60 Clear thread pool task data on restart 2024-06-02 14:54:32 -04:00
Feoramund 558c330028 Add task-stopping functionality to thread.Pool 2024-06-02 14:34:30 -04:00
gingerBill f9fd8f0c25 Merge pull request #3439 from andreas-jonsson/netbsd
NetBSD support
2024-05-15 10:33:52 +01:00
gingerBill 54ebfa6179 Fix hanging on thread.join for windows where the thread had not been started 2024-05-13 12:58:18 +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
gingerBill 29e5f94c2a Add #no_broadcast procedure parameter to disallow automatic array programming broadcasting on procedure arguments 2024-03-21 11:52:48 +00: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 90ac400ec5 stdcall -> system 2024-01-17 17:25:23 +00:00
Laytan Laats 9078ddaf5a Allow larger thread poly data
The poly data currently has the restriction of being less than a
pointer's size, but there is much more space in the `Thread.user_args`
array which can be utilized, this commit allows you to pass types that are
larger than pointer length as long as the total size of the poly data is
less than that of the `Thread.user_args`.
2023-11-15 19:08:03 +01:00
flysand7 270348b112 [core]: Remove do keyword from the core library 2023-11-11 20:36:38 +11:00
gingerBill 2cc22d118d Require parentheses for #align(N) 2023-08-15 14:55:02 +01:00
gingerBill 44ea82f845 Clean up usage of using throughout core and vendor 2023-07-31 11:46:40 +01:00
gingerBill 3dec55f009 Replace x in &y Use &v in y syntax through core & vendor for switch/for statements 2023-06-26 15:42:57 +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
gingerBill c194dfbdf7 Remove thread.init_context = context 2023-05-31 22:23:47 +01:00
Dragos Popescu b2ecb37b35 Changed js panics to unimplemented where sensible 2023-03-22 12:10:27 +01:00
Dragos Popescu ef3d8bdc42 Fixed more compile time errors when including os and thread to js targets 2023-03-21 04:17:31 +01:00
Dragos Popescu adac039a2b Made most libraries panic on js targets instead of not compiling 2023-03-20 04:08:48 +01:00
Jeroen van Rijn 85edcf9cc2 Revert. 2022-05-14 13:34:52 +02:00