3 ms·
I wrote an unrolled switch statement in Java to simulate eager async/await across threads. https://github.com/samsquire/multiversion-concurrency-control/blob/m
by samsquire 4y ago
I wrote an unrolled switch statement in Java to simulate eager async/await across threads.
https://github.com/samsquire/multiversion-concurrency-control/blob/main/src/main/java/main/MultiAwait.java https://github.com/samsquire/multiversion-concurrency-contro...
The goal is that a compiler should generate this for you. This code is equivalent to the following:
task1:
while True:
handle1 = async task2();
handle2 = async task3();
print(await handle1)
print(await handle2)
task2:
n = 0
while True:
yield n++
task3:
n = 0
while True:
yield n++
It doesn't actually run task2 and task3 both eagerly, I've not got around to scheduling the tasks on DIFFERENT threads. They currently queue onto a single thread, so task2 and task3 are parallel to task1 (but maybe not at the same time) but task2 and task3 are not parallel to each other. This is my goal.
I also ported the coroutines in this blog post https://blog.dziban.net/coroutines/ https://blog.dziban.net/coroutines/
to GNU Assembler
https://github.com/samsquire/assembly/blob/main/coroutines.S https://github.com/samsquire/assembly/blob/main/coroutines.S
This might be useful to someone who wants to port this to C. This uses the stack switching idea. So they are stackful coroutines.
There's also Tina a header only coroutine library
https://slembcke.github.io/Tina https://slembcke.github.io/Tina
I also played with protothreads
http://dunkels.com/adam/pt/ http://dunkels.com/adam/pt/
I also asked in a stackoverflow post how to use a thread pool with C++20 coroutines:
https://stackoverflow.com/questions/74520133/how-can-i-pass-things-to-a-c20-coroutine-co-await-await-suspend-operator-funct https://stackoverflow.com/questions/74520133/how-can-i-pass-...
Someone provided some example code, which seems to work with C++ coroutines :-)