aboutsummaryrefslogtreecommitdiff
path: root/lib/std/Thread
AgeCommit message (Collapse)Author
2024-11-11Revert "Enable thread_pool function to throw errors (#20260)"Andrew Kelley
This reverts commit d346d074ebe5347f730a70d3a88b12f279bb405d. I would like a chance to review this, please.
2024-11-11Enable thread_pool function to throw errors (#20260)ippsav
* std.ThreadPool: allow error union return type * allow noreturn in Pool.zig
2024-10-23combine codegen work queue and linker task queueAndrew Kelley
these tasks have some shared data dependencies so they cannot be done simultaneously. Future work should untangle these data dependencies so that more can be done in parallel. for now this commit ensures correctness by making linker input parsing and codegen tasks part of the same queue.
2024-10-04remove `@fence` (#21585)David Rubin
closes #11650
2024-09-11thread: don't leak the thread in `spawnManager` (#21379)David Rubin
2024-08-27compiler,lib,test,langref: migrate `@setCold` to `@branchHint`mlugg
2024-07-19std.c reorganizationAndrew Kelley
It is now composed of these main sections: * Declarations that are shared among all operating systems. * Declarations that have the same name, but different type signatures depending on the operating system. Often multiple operating systems share the same type signatures however. * Declarations that are specific to a single operating system. - These are imported one per line so you can see where they come from, protected by a comptime block to prevent accessing the wrong one. Closes #19352 by changing the convention to making types `void` and functions `{}`, so that it becomes possible to update `@hasDecl` sites to use `@TypeOf(f) != void` or `T != void`. Happily, this ended up removing some duplicate logic and update some bitrotted feature detection checks. A handful of types have been modified to gain namespacing and type safety. This is a breaking change. Oh, and the last usage of `usingnamespace` site is eliminated.
2024-07-15Better implementation of GetLastError. (#20623)Lucas Santos
Instead of calling the dynamically loaded kernel32.GetLastError, we can extract it from the TEB. As shown by [Wine](https://github.com/wine-mirror/wine/blob/34b1606019982b71818780bc84b76460f650af31/include/winternl.h#L439), the last error lives at offset 0x34 of the TEB in 32-bit Windows and at offset 0x68 in 64-bit Windows.
2024-07-09test: Add `spawn` behavior testmochalins
2024-07-09fix: Update `spawn`'s' `runFn` signaturemochalins
2024-07-08Compilation: put supported codegen backends on a separate threadJacob Young
(There are no supported backends.)
2024-07-07InternPool: implement and use thread-safe list for extra and limbsJacob Young
2024-07-07InternPool: temporarily disable multi-threaded behaviorJacob Young
This reduces the cost of the new data structure until the multi-threaded behavior is actually used.
2024-07-07InternPool: implement thread-safe hash mapJacob Young
2024-07-07Zcu: introduce `PerThread` and pass to all the functionsJacob Young
2024-06-12std.Thread.Mutex.Recursive: alternate implementationAndrew Kelley
This version is simpler. Thanks King!
2024-06-12introduce std.Thread.Mutex.RecursiveAndrew Kelley
2024-05-03add std.Thread.Pool.spawnWgAndrew Kelley
This function accepts a WaitGroup parameter and manages the reference counting therein. It also is infallible. The existing `spawn` function is still handy when the job wants to further schedule more tasks.
2024-04-24Clarify the blocking behavior of `RwLock.lockShared()`. (#19752)IntegratedQuantum
2024-04-19std: fix Thread.Pool.spawnGethDW
`@alignCast` was required for args with greater alignment than that of a pointer.
2024-03-30Update uses of `@fieldParentPtr` to use RLSJacob Young
2024-03-30Update uses of `@fieldParentPtr` to pass a pointer typeJacob Young
2024-03-20bsd: followup to std.posix extraction from std.osMichael Dusan
netbsd fix: - `Futex.zig:542:56: error: expected error union type, found 'c_int'` openbsd fix: - `emutls.zig:10:21: error: root struct of file 'os' has no member named 'abort'` - `Thread.zig:627:22: error: expected 6 argument(s), found 5`
2024-03-19extract std.posix from std.osAndrew Kelley
closes #5019
2024-03-15bsd: debitrot AtomicOrder renamesMichael Dusan
- complete std.builtin.AtomicOrder renames that were missed from 6067d39522f
2024-03-11std.builtin: make atomic order fields lowercaseTristan Ross
2024-03-10std.Thread.WaitGroup: add spawnManagedAndrew Kelley
Provides a convenient way to spawn a new thread that bypasses a thread pool. Appropriate when the spawned thread delegates all of its work.
2024-02-26Change many test blocks to doctests/decltestsRyan Liptak
2024-02-26Remove redundant test name prefixes now that test names are fully qualifiedRyan Liptak
Follow up to #19079, which made test names fully qualified. This fixes tests that now-redundant information in their test names. For example here's a fully qualified test name before the changes in this commit: "priority_queue.test.std.PriorityQueue: shrinkAndFree" and the same test's name after the changes in this commit: "priority_queue.test.shrinkAndFree"
2024-02-13Add `timedWait` to `std.Thread.Semaphore` (#18805)Felix Kollmann
* Add `timedWait` to `std.Thread.Semaphore` Add example to documentation of `std.Thread.Semaphore` * Add unit test for thread semaphore timed wait Fix missing try * Change unit test to be simpler * Change `timedWait()` to keep a deadline * Change `timedWait()` to return earlier in some scenarios * Change `timedWait()` to keep a deadline (based on std.Timer) (similar to std.Thread.Futex) --------- Co-authored-by: protty <45520026+kprotty@users.noreply.github.com>
2024-02-08Replace std.rand references with std.Randome4m2
2024-01-22Free threads in std.Thread.Pool.init only with pool.joinLittleote
Free the allocated threads in the initialization of a thread pool only with pool.join instead of additionally calling allocator.free causing free to be called twice. Resolves #18643
2023-11-26bsd: debitrot atomic and debugMichael Dusan
closes #18119
2023-11-22rework std.atomicAndrew Kelley
* move std.atomic.Atomic to std.atomic.Value * fix incorrect argument order passed to testing.expectEqual * make the functions be a thin wrapper over the atomic builtins and stick to the naming conventions. * remove pointless functions loadUnchecked and storeUnchecked. Instead, name the field `raw` instead of `value` (which is redundant with the type name). * simplify the tests by not passing every possible combination. Many cases were iterating over every possible combinations but then not even using the for loop element value! * remove the redundant compile errors which are already implemented by the language itself. * remove dead x86 inline assembly. this should be implemented in the language if at all.
2023-11-19lib: correct unnecessary uses of 'var'mlugg
2023-11-03x86_64: fix std test failuresJacob Young
2023-10-31std/Thread: remove unnecessary `@ptrCast` (#17766)XXIV
2023-10-29x86_64: fix compiler rt test failuresJacob Young
2023-10-25x86_64: pass more testsJacob Young
* 128-bit integer multiplication with overflow * more instruction encodings used by std inline asm * implement the `try_ptr` air instruction * follow correct stack frame abi * enable full panic handler * enable stack traces
2023-10-23x86_64: implement 128-bit builtinsJacob Young
* `@clz` * `@ctz` * `@popCount` * `@byteSwap` * `@bitReverse` * various encodings used by std
2023-10-22Revert "Revert "Merge pull request #17637 from jacobly0/x86_64-test-std""Jacob Young
This reverts commit 6f0198cadbe29294f2bf3153a27beebd64377566.
2023-10-22Revert "Merge pull request #17637 from jacobly0/x86_64-test-std"Andrew Kelley
This reverts commit 0c99ba1eab63865592bb084feb271cd4e4b0357e, reversing changes made to 5f92b070bf284f1493b1b5d433dd3adde2f46727. This caused a CI failure when it landed in master branch due to a 128-bit `@byteSwap` in std.mem.
2023-10-21x86_64: disable failing tests, enable test-std testingJacob Young
2023-07-26Fix counting in SingleThreadedRwLock's tryLockShared (#16560)Jim Price
Additionally we add RwLock to Thread.zig's list of tests
2023-06-26std: implement `detach` for WASI-threadsLuuk de Gram
When a thread is detached from the main thread, we automatically cleanup any allocated memory. For this we first reset the stack-pointer to the original stack-pointer of the main-thread so we can safely clear the memory which also contains the thread's stack.
2023-06-26std: implement `Futex` for WebAssemblyLuuk de Gram
Implements std's `Futex` for the WebAssembly target using Wasm's `atomics` instruction set. When the `atomics` cpu feature is disabled we emit a compile-error.
2023-06-24all: migrate code to new cast builtin syntaxmlugg
Most of this migration was performed automatically with `zig fmt`. There were a few exceptions which I had to manually fix: * `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten * `@truncate`'s fixup is incorrect for vectors * Test cases are not formatted, and their error locations change
2023-06-20std: prevent random CI failuresJacob Young
2023-06-19all: zig fmt and rename "@XToY" to "@YFromX"Eric Joldasov
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-05-20Zir: eliminate `field_call_bind` and `field_call_bind_named`mlugg
This commit removes the `field_call_bind` and `field_call_bind_named` ZIR instructions, replacing them with a `field_call` instruction which does the bind and call in one. `field_call_bind` is an unfortunate instruction. It's tied into one very specific usage pattern - its result can only be used as a callee. This means that it creates a value of a "pseudo-type" of sorts, `bound_fn` - this type used to exist in Zig, but now we just hide it from the user and have AstGen ensure it's only used in one way. This is quite silly - `Type` and `Value` should, as much as possible, reflect real Zig types and values. It makes sense to instead encode the `a.b()` syntax as its own ZIR instruction, so that's what we do here. This commit introduces a new instruction, `field_call`. It's like `call`, but rather than a callee ref, it contains a ref to the object pointer (`&a` in `a.b()`) and the string field name (`b`). This eliminates `bound_fn` from the language, and slightly decreases the size of generated ZIR - stats below. This commit does remove a few usages which used to be allowed: - `@field(a, "b")()` - `@call(.auto, a.b, .{})` - `@call(.auto, @field(a, "b"), .{})` These forms used to work just like `a.b()`, but are no longer allowed. I believe this is the correct choice for a few reasons: - `a.b()` is a purely *syntactic* form; for instance, `(a.b)()` is not valid. This means it is *not* inconsistent to not allow it in these cases; the special case here isn't "a field access as a callee", but rather this exact syntactic form. - The second argument to `@call` looks much more visually distinct from the callee in standard call syntax. To me, this makes it seem strange for that argument to not work like a normal expression in this context. - A more practical argument: it's confusing! `@field` and `@call` are used in very different contexts to standard function calls: the former normally hints at some comptime machinery, and the latter that you want more precise control over parts of a function call. In these contexts, you don't want implicit arguments adding extra confusion: you want to be very explicit about what you're doing. Lastly, some stats. I mentioned before that this change slightly reduces the size of ZIR - this is due to two instructions (`field_call_bind` then `call`) being replaced with one (`field_call`). Here are some numbers: +--------------+----------+----------+--------+ | File | Before | After | Change | +--------------+----------+----------+--------+ | Sema.zig | 4.72M | 4.53M | -4% | | AstGen.zig | 1.52M | 1.48M | -3% | | hash_map.zig | 283.9K | 276.2K | -3% | | math.zig | 312.6K | 305.3K | -2% | +--------------+----------+----------+--------+