Commit graph

433 commits

Author SHA1 Message Date
breakmit
46658257f4 Io.Threaded.spawnPosix: implement passing file descriptors as stdio (#31379)
`std.process.spawn`: remove the TODO for nonblocking file stdio and document the behavior.

Fix a bug in Io.Uring.dup2 where the function does not return on success

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31379
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: breakmit <breakmit@noreply.codeberg.org>
Co-committed-by: breakmit <breakmit@noreply.codeberg.org>
2026-03-06 04:51:28 +01:00
xeondev
15f0af09d0 Io.Threaded.batchAwaitConcurrent: fix poll args 2026-03-05 20:17:21 +01:00
Andrew Kelley
02142a54d2 std.Io: remove cancelation propagation assertions
While the general guidance remains useful, it is not the case that
error.Canceled will always pass across the Group task function boundary.

Remove the too-aggressive assertions and add unit test coverage.

Closes #30096
Closes #31340
Closes #31358
2026-02-28 05:07:54 +01:00
vitalii
1838134200 fix segfault when /etc/hosts missing last newline 2026-02-15 23:12:13 +01:00
Andrew Kelley
d9fc7fa04d std.Io: remove select function
This function works with a slice of futures and returns the index of a
completed one. This doesn't work very well in practice because it's
either too high level or too low level.

At the lower level we have Io.Batch for doing this kind of thing at the
Operation API layer.

At the higher level we have Io.Select which is a convenience wrapper
around an Io.Group and an Io.Queue.
2026-02-14 18:31:48 -08:00
Andrew Kelley
d2c862e6ff Merge pull request 'Io.Dispatch: introduce grand central dispatch io impl' (#31198) from dispatch into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31198
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-02-13 23:19:32 +01:00
hubidubi
fd74c5742d std.Io.Threaded: fix FreeBSD Futex max_waiters (#30094)
On FreeBSD, the maximum waiters should be Cs INT_MAX instead of the maximum of a u32. Waiting for the Io.Event in the broadcast test triggers this bug.

Resolves #30715

Co-authored-by: Simon Galli <hubi@hubidubi.net>
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30094
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: hubidubi <hubidubi@noreply.codeberg.org>
Co-committed-by: hubidubi <hubidubi@noreply.codeberg.org>
2026-02-13 20:39:38 +01:00
Jacob Young
2fa1a78491 Io.Dispatch: introduce grand central dispatch io impl 2026-02-13 12:29:40 -05:00
Andrew Kelley
b600b6e5e0 std.posix: remove close function 2026-02-11 23:37:31 +01:00
Jacob Young
7369008d8c Io.IoUring: implement some thread pool options and other cleanup 2026-02-10 23:45:48 +01:00
Jacob Young
a28d57292f IoUring: update to new Io APIs 2026-02-09 10:47:21 -05:00
Jacob Young
b5bd494606 std.Threaded: replace more kernel32 functions with ntdll 2026-02-07 00:02:50 -05:00
Andrew Kelley
76d275b20f std.Io.Threaded: flatten some switch cases 2026-02-05 16:30:33 -08:00
Jacob Young
c77e7146f5 std.Threaded: replace console kernel32 functions with ntdll 2026-02-05 07:41:25 -05:00
Andrew Kelley
3078a3197b std.Io.Threaded.dirCreateDirWindows: remove unexpected error handling 2026-02-04 16:30:19 -08:00
Andrew Kelley
0e7d00776e std.Io.Threaded: inline OpenFile into dirCreateDirWindows 2026-02-04 16:30:19 -08:00
Andrew Kelley
3a5fff45ec std: move os.windows.OpenFile into Io.Threaded
it needs cancelation integration
2026-02-04 16:30:17 -08:00
Andrew Kelley
2a193a3987 std: move GetFinalPathNameByHandle to Io.Threaded
unfortunately this function calls NtCreateFile so it has to participate
in cancelation
2026-02-04 16:27:13 -08:00
Andrew Kelley
fcef9905ae Merge pull request 'std.Progress: implement inter-process progress reporting for windows' (#31113) from threaded-win-cleanup into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31113
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-02-05 01:24:18 +01:00
Jacob Young
71156aff80 std.Progress: implement ipc resource cleanup 2026-02-04 15:20:10 -05:00
Matthew Lugg
a816f9e245
std.Io.Threaded: use _lwp_park correctly for real this time? 2026-02-04 20:44:37 +01:00
Matthew Lugg
fcdde3e4c7
std.Io.Threaded: gracefully handle race leading to ESRCH in unpark() 2026-02-04 20:44:37 +01:00
Jacob Young
ffc6da29e3 std.Io.Threaded: implement and cleanup windows codepaths 2026-02-04 14:15:41 -05:00
Andrew Kelley
d45f9aca14 std.Thread: delete Mutex.Recursive
Replaced by the lockStderr functions of std.Io. Trying to make
`std.process.stderr_thread_mutex` be a bridge across different Io
implementations didn't work in practice.
2026-02-03 20:46:25 -08:00
Andrew Kelley
d1e01e9431 Merge pull request 'std.Io.Threaded: Windows *cannot* spuriously unpark, and introduce ParkingMutex' (#31102) from parking-futex-parking-mutex into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31102
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-02-04 05:06:17 +01:00
Matthew Lugg
6d6532dd9e
Io.Threaded: add ParkingMutex, and deal with spurious unparks on NetBSD
We can't use Io.Mutex in parking_futex; instead, we need a simple
parking-based mutex implementation. That's fairly simple to do.

Also deal with spurious unparks on NetBSD, where they *can* happen (as
opposed to Windows, where they cannot).
2026-02-03 22:50:35 +00:00
Matthew Lugg
7c08f77efa
Revert "std.Io.Threaded: spurious unparks are possible"
It turns out that at least on Windows, spurious unparks are *not*
possible, and in fact triggering them breaks some RTL synchronization
primitives. For instance, if you have a pending unpark going into a
contended `RtlEnterCriticalSection` call, it will never unblock. In
other words, the Windows API worked exactly how I thought it did, and
it's only the NetBSD/Illumos one which is dumb. This is actually exactly
why Windows 8 introduced the parking API despite alertable sleeps being
a thing!

This commit doesn't yet deal with making NetBSD work, nor does it even
compile I imagine. The next commit will fix everything back up.

This reverts commit c518593e97.
2026-02-03 22:47:19 +00:00
Matthew Lugg
56a43fb86f
Revert "std.Io.Threaded: work around parking futex bug"
This reverts commit 5312063138.
2026-02-03 22:38:28 +00:00
Andrew Kelley
1ab5a58474 std.Io.Threaded: handle errors from clockResolution 2026-02-03 12:00:14 -08:00
Andrew Kelley
fe5da36aa3 std.Io make Clock.resolution fallible 2026-02-03 01:02:48 -08:00
Andrew Kelley
922ab8b8bc std: finish moving time to Io interface
Importantly, adds ability to get Clock resolution, which may be zero.
This allows error.Unexpected and error.ClockUnsupported to be removed
from timeout and clock reading error sets.
2026-02-02 23:02:31 -08:00
Andrew Kelley
4c4e9d054e std.Io: add RwLock and Semaphore sync primitives
and restore usage by std.debug.SelfInfo.Elf
2026-02-02 20:18:14 -08:00
Andrew Kelley
550da1b676 std: migrate remaining sync primitives to Io
- delete std.Thread.Futex
- delete std.Thread.Mutex
- delete std.Thread.Semaphore
- delete std.Thread.Condition
- delete std.Thread.RwLock
- delete std.once

std.Thread.Mutex.Recursive remains... for now. it will be replaced with
a special purpose mechanism used only by panic logic.

std.Io.Threaded exposes mutexLock and mutexUnlock for the advanced case
when you need to call them directly.
2026-02-02 18:57:17 -08:00
Andrew Kelley
5312063138 std.Io.Threaded: work around parking futex bug
This commit should be reverted - it's testing a hypothesis that Windows
is deadlocking due to bug in the implementation of
std.Io.Threaded.parking_futex
2026-02-02 14:25:27 -08:00
Andrew Kelley
eb74e23e7b std.Io.Threaded: sever dependency on std.Thread Mutex and Condition 2026-02-02 14:18:04 -08:00
Andrew Kelley
c2d4806d65 Merge pull request 'std.Thread: remove redundant sync APIs ResetEvent and WaitGroup' (#31088) from sync-cleanup-smaller into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31088
2026-02-02 23:14:05 +01:00
Krzysztof Antonowski
1cd3af43fd std.Io.Threaded: implement CPU-based clocks on Windows (#31093)
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31093
Co-authored-by: Krzysztof Antonowski <krzysztofantonowski@proton.me>
Co-committed-by: Krzysztof Antonowski <krzysztofantonowski@proton.me>
2026-02-02 22:19:19 +01:00
Andrew Kelley
633eb247ab std.Io.Event: fix single-threaded implementation 2026-02-02 10:44:50 -08:00
Ryan Liptak
05346e123b Add process.Child.Cwd, use it for cwd and remove cwd_dir field
The user must now explicitly choose between inheriting the current CWD, passing a path for the CWD, or passing a Dir for the CWD.
2026-02-02 01:41:35 -08:00
Tom Winter
83abd73801 Windows: Support directory handle for cwd instead of string for Child.process
This implementation is a bit of a hacky workaround, as we use a ntdll
API to grab the full path of the directory handle. As far as I can tell
this might be the only solution to the problem, as
kernel32.CreateProcessW takes a directory path as a string only.

I might be wrong though as haven't researched the problem thoroughly.
2026-02-02 01:21:11 -08:00
Andrew Kelley
b191e50be5 std.Thread: remove ResetEvent and WaitGroup
* std.Thread.ResetEvent -> Io.Event
* std.Thread.WaitGroup -> Io.Group
2026-02-02 00:09:48 -08:00
Andrew Kelley
59073484ba std.Io: add ioctl / DeviceIoControlFile API 2026-02-01 01:08:01 -08:00
Andrew Kelley
cc442d24ab std.Io: move fileWriteStreaming to Operation
This serves as an example to contributors of how to move VTable
functions to becoming an Operation, thereby enabling Batch API and
timeouts.
2026-01-31 22:53:28 -08:00
Andrew Kelley
3abc96a601 std.Io: add test for batchAwaitAsync
and make it always work for all targets including WASI

This function guarantees no additional failure modes introduced.
2026-02-01 02:49:36 +01:00
Andrew Kelley
2b19134c86 Merge pull request 'std.Io: introduce batching and operations API, satisfying the "poll" use case' (#30743) from poll into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30743
2026-01-31 12:07:31 +01:00
Andrew Kelley
b6f4bb91c4 std.Io: add documentation to Batch 2026-01-30 22:03:33 -08:00
Andrew Kelley
25aef0dd87 std.Io.Threaded: rework file reading to observe nonblocking flag
- batchAwaitAsync does blocking reads with NtReadFile (no APC, no event)
  when the nonblocking flag is unset, but still takes advantage of
  APCs when nonblocking flag is set.
- batchAwaitConcurrent returns error.ConcurrencyUnavailable when it
  encounters a file_read_streaming operation on a file in blocking mode.
- fileReadStreaming avoids pointlessly checking sync cancelation status
  when nonblocking flag is set, uses an APC with a done flag, and waits
  on that value to change in NtDelayExecution before returning.
- fix incorrect use of NtCancelIoFile (ntdll function prototype was
  wrong, leading to misuse)
2026-01-30 22:03:14 -08:00
Andrew Kelley
39a6d5d1c5 std.Io.File: add non-blocking flag
On Windows, we need to know ahead of time whether a file was opened in
synchronous mode or asynchronous mode. There may be advantages to
tracking this state for POSIX operating systems as well.
2026-01-30 22:03:14 -08:00
Andrew Kelley
62c97b745d std.Io.Threaded: stop checking bytes read with END_OF_FILE 2026-01-30 22:03:14 -08:00
Jacob Young
2674acdb77 Io.Batch: implement alternate API 2026-01-30 22:03:14 -08:00