New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add event loop Channel abstraction #1173
Conversation
Can we discuss whether there should be a coroutine <=> thread mapping? I think it should be explicit and user-controlled. Otherwise performance guarantees can be hard to establish (consider NUMA cache optimization.) Also, I suggest being a little careful with the Go analogy since Go channels are built on mutex locking, and are typically used as a synchronization device. I'm not that familiar with lock-free queues, but wouldn't they be non-blocking? I.e., no "await" or blocking "select" or "for _ = range x" or whatnot. |
The coroutines and thread mapping is entirely in userland and will be an option that std.event.Loop provides. The implementation is lock free but it integrates with coroutines, and the get() and put() functions of Channel are async. So you define the channel buffer size (possibly zero) and that many put() awaits will resolve immediately. The next put() await will resume when the next get() completes. So it still acts like a synchronization device, with async/await. |
This is akin to channels in Go, except: * implemented in userland * they are lock-free and thread-safe * they integrate with the userland event loop The self hosted compiler is changed to use a channel for events, and made to stay alive, watching files and performing builds when things change, however the main.zig file exits after 1 build. Note that nothing is actually built yet, it just parses the input and then declares that the build succeeded. Next items to do: * add windows and macos support for std.event.Loop * improve the event loop stop() operation * make the event loop multiplex coroutines onto kernel threads * watch source file for updates, and provide AST diffs (at least list the top level declaration changes) * top level declaration analysis
01e3fb8
to
96a6bc5
Compare
Exiting news ! |
FWIW, I think this broke the self-hosted build on my Mac.
|
can you try this? --- a/src-self-hosted/module.zig
+++ b/src-self-hosted/module.zig
@@ -115,6 +115,7 @@ pub const Module = struct {
InputOutput,
NoStdHandles,
Overflow,
+ NotSupported,
};
pub const Event = union(enum) { I'll clean this up soon. |
That did the trick! |
This is akin to channels in Go, except:
The self hosted compiler is changed to use a channel for events,
and made to stay alive, watching files and performing builds when
things change, however the main.zig file exits after 1 build.
Note that nothing is actually built yet, it just parses the input
and then declares that the build succeeded.
Next items to do:
(at least list the top level declaration changes)