-
Notifications
You must be signed in to change notification settings - Fork 2
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
Time based fiber yield points #15
Comments
Note: more yielding points means that cooperative shutdown or cooperative stop-the-world, or fiber cancellations could happen faster. |
I got the logic implemented:
It works. A busy loop that manually checks for But I quickly get a
And an eventual crash:
(*) more places could eventually call |
Note about the crash: this is the EDIT: this may happen if:
NOTE: had it been a MT context, the thread would have deadlock, waiting for the current fiber to be resumable. |
I think the issue is the monitoring thread telling the runloop fibers to interrupt then the event calling Fiber#enqueue to enqueue fibers.
|
That fixed the issue. |
CPU bound fibers may never hit a cancellation point, and block a thread to run a fiber for an unbounded amount of time, blocking other fibers from running.
I'm not even talking about CPU heavy algorithms (e.g. cryptography): a regular sockets may prevent a fiber from yielding, for example when the socket's always ready for read or write (the fiber will never wait on the event loop); a buffered Channel won't suspend the current fiber until the buffer is full or empty, which may take a while to happen if the other end is pushing/consuming them quickly.
One goal of execution contexts is to limit this in practice, by taking advantage of the OS to preempt threads. Still, we should have more places places that can yield the current fiber.
For example
Fiber#enqueue
could check for how long the current fiber has been running and decide to yield when it ran for N milliseconds. MaybeIO
methods could do just that (inside the EventLoop). Instead of checkingTime.monotonic
over and over again, we could have the monitoring thread do the check and mark the fiber (see #5).The text was updated successfully, but these errors were encountered: