News for hackers. Stuff that matters.
Re:Zig's new plan for asynchronous programs by ethin on Tuesday December 02, 2025 @12:05PM (#46123463)
One thing the old Zig async/await system theoretically allowed me to do, which I'm not certain how to accomplish with this new io system without manually implementing it myself, is suspend/resume. Where you could suspend the frame of a function and resume it later. I've held off on taking a stab at OS dev in Zig because I was really, really hoping I could take advantage of that neat feature: configure a device or submit a command to a queue, suspend the function that submitted the command, and resume it when an interrupt from the device is received. That was my idea, anyway. Idk if that would play out well in practice, but it was an interesting idea I wanted to try.
Re:Zig's new plan for asynchronous programs by NooneAtAll3 on Tuesday December 02, 2025 @12:09PM (#46123520)
what's the point of implementing cooperative "multithreading" (coroutines) with preemptive one (async)?
Re:Zig's new plan for asynchronous programs by wchar_t on Tuesday December 02, 2025 @09:06PM (#46129474)
There was this beautiful little time period where async/await was basically just that: resumable functions. I abused it to implement generators.
Re:Zig's new plan for asynchronous programs by nine_k on Tuesday December 02, 2025 @12:52PM (#46124109)
Can you create a thread pool consisting of one thread, and suspend / resume the thread?
Re:Zig's new plan for asynchronous programs by RossBencina on Tuesday December 02, 2025 @04:52PM (#46127403)
Doesn't that negate the point of using coroutines? light-weight concurrency
Re:Zig's new plan for asynchronous programs by nine_k on Tuesday December 02, 2025 @10:05PM (#46129826)
It does, sadly.
Re:Zig's new plan for asynchronous programs by ethin on Wednesday December 03, 2025 @10:51AM (#46135888)
I mean I guess I could... But threads are pretty heavyweight. Though there may be a more lightweight way of implementing them in kernel mode (not coroutines or fibers, but actual threads) and I just have never heard of it.
Re:Zig's new plan for asynchronous programs by your_sweetpea on Tuesday December 02, 2025 @11:00PM (#46130165)
I suspect the end goal is to have suspend/resume (or some analogue) be userspace standard library functions used to implement Io.Evented. It'll end up being a userspace implementation like you see with many of the C coroutine libraries floating around on GitHub (minicoro, llco, etc).

Edit: Looking at the working prototype of Io.Evented, this may not be true actually. Perhaps this is the domain of a 3rd-party library except with stackless coroutines?

Another thing you may want to pay attention to, however, are the current proposals for getting evented IO working on WASM -- namely, stackless coroutines as a language feature: https://github.com/ziglang/zig/issues/23446

Re:Zig's new plan for asynchronous programs by throwawaymaths on Wednesday December 03, 2025 @09:17AM (#46134730)
> suspend/resume

special @asyncSuspend and @asyncResume builtins, they will be the low level detail you can build an evented io with.

new Io is an abstraction over the higher level details that are common between sync, threaded, and evented, so you shouldn't expect the suspension mechanism to be in it.

Re:Zig's new plan for asynchronous programs by ethin on Wednesday December 03, 2025 @10:49AM (#46135852)
Oh really? That's perfect.