← Back to team overview

kicad-developers team mailing list archive

Re: KiCad Coroutines

 

Hi Wayne,
 
> What version(s) of Windows support fibers? I didn't see any indication
> on the links above.
 
See this link:

https://support.microsoft.com/en-us/kb/128531

Fibers were added to the WIN32-API with the Service Pack 5 for Windows NT 3.51.

Quote from the above link:

"[..] 
Service Pack 5 contains 3 additions to the Win32 API:

Fibers
------
A fiber is a lightweight thread that is manually scheduled.  Fibers do not
provide advantages over a well-designed multithreaded application.
However, fibers can make it easier to port applications that were designed
to schedule their own threads.
[..]"

So any actual desktop Windows version (XP and later) should support these functions.

I've tried the provided example from Microsoft on MSYS2 / Windows 10 (64 Bit) and it was running well.

> I don't have any strong opinions either way. However, I did not write
> the code. Tom may have a stronger opinion about this than I do since he
> wrote the code. Personally I'm not the biggest fan of coroutines. I
> know the make the code easier to read but I'm not convinced they are
> necessary in an event driven design.

This is true, but as you have written - the code is easier to read. Another alternatives would be to use state machines (with switch/case etc.) or stackless coroutines (Protothreads are an example, https://en.wikipedia.org/wiki/Protothreads). In Python are Coroutines a language concept, see also https://wiki.python.org/moin/Generators .

An example use case would be a long running computation, with a coroutine you could yield to the main thread and update a status bar or similar. 
 
Thanks,
Torsten


References