4 ms·
To refer to the post, I don't know how a tail call optimisation would look for a coroutine. My async/await implementation has overhead of scheduling but the sch
by samsquire 4y ago
To refer to the post, I don't know how a tail call optimisation would look for a coroutine. My async/await implementation has overhead of scheduling but the scheduler is very simple.
Above this code is a switch statement and it's in a loop. The nestged switch statement switches on currentTask and loop task state.
for (int i = -1; i < state.size(); i++) {
int task = (currentTask + i + 1) % state.size();
if (state.get(task) == 0) {
currentTask = task;
}
}
No stack but 3 integers are used per coroutine. How do you have multiple instances of coroutines without destroying state of each one?
I am interested in coroutines and there's a corollary between recursion and coroutines and stacks.
I am trying to work out how to implement coroutines or async/await. I've written an unrolled switched based multithreaded implementation. Currently coroutines can async fork/eagerly start on another thread but it only supports one forked coroutine at a time at this time. This is similar to other async/await engines.
You can have stackful coroutines (allocated on the heap) or stackless coroutines data presumably in your stackful langauage as a local variable or class variable or global.
If I have N coroutines, I need to allocate three integers for each coroutine instance. One is the task state which is running or not running. Then there is integer/string for top level state (where in the coroutine are we) and then there is loop level state. A coroutine can be executing in any depth of loops, but these two integers or strings in my case represent all execution environments.
Code of my unrolled state machine that uses switch statements and multithreading is here
https://github.com/samsquire/multiversion-concurrency-control/blob/main/src/main/java/main/TokenRingTimer2AsyncAwait3.java https://github.com/samsquire/multiversion-concurrency-contro...
I want to redesign the architecture of the async/await to be easier to understand. I want to use a state machine somehow.
- mgaunard 4y agoIt's the same. A coroutine that does ``` lazy<int> f(int i) { if (i == 0) co_return i; co_return co_await f(i-1); } ``` should be tail-optimized.