Fibers talk by Mikola Lysenko

Mikola Lysenko mikolalysenko at gmail.com
Sun Oct 5 21:40:26 PDT 2008


In short: Yes.



bearophile Wrote:

> - In Python you have yield, but it can also take parameters, so the two coroutines can send messages to each other all the time. I presume this is possible with those fibers too.

Daniel Keep did this long ago using StackThreads.  The general idea behind Fibers is to provide a low-level, low-overhead mechanism for getting implementing more complex behaviors.  As a consequence, it was deemed unnecessary to put this kind of feature in the core runtime.

> - It's good to not have to change the language to implement them. But if you can change the language a little, what kind of syntactic sugar can you find useful for them?

I'd basically add a yield statement and a way to automatically wrap parameters.  This would let you do something like the following:

int delegate(int) dg = cocreate (int x) { yield x + 2; yield x +5; }
print(dg(1));
print(dg(2));

//Prints out:
// 3
// 7

> - A few benchmarks to compare the performance of fibers compared to normal plain subroutines (and opApply) can be useful.

I have some older benchmarks from stackthreads, but I lost them when I changed web hosts.  I am currently planning on building a profiling suite for tuning performance on various systems.

In theory, it would be very difficult to get much faster as the cost per switch is on the order of 10 cpu instructions.  In practice, you will sill pay something due to cache misses.

> - If programmers start using fibers often, then can it become positive for the compiler to be aware of them, to optimize code better? (especially when they are used where they aren't necessary).

A compiler implementation could avoid unnecessary register saves, inline context switching and make parameter passing automatic.



Regards,
-Mik


More information about the Digitalmars-d-announce mailing list