kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #22382
Re: KiCad Coroutines
-
To:
Kicad Developers <kicad-developers@xxxxxxxxxxxxxxxxxxx>
-
From:
Tomasz Wlostowski <tomasz.wlostowski@xxxxxxx>
-
Date:
Thu, 7 Jan 2016 13:53:39 +0100
-
Authentication-results:
spf=pass (sender IP is 188.184.36.50) smtp.mailfrom=cern.ch; lists.launchpad.net; dkim=none (message not signed) header.d=none;lists.launchpad.net; dmarc=bestguesspass action=none header.from=cern.ch;
-
In-reply-to:
<20160107123405.GG4139@yuki.logos.lan>
-
Spamdiagnosticmetadata:
NSPM
-
Spamdiagnosticoutput:
1:23
-
User-agent:
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0
On 07.01.2016 13:34, Lorenzo Marcantonio wrote:
> On Thu, Jan 07, 2016 at 12:08:22PM +0000, Mário Luzeiro wrote:
>> Hi all,
>>
>> Sorry I don't know nothing about co-routines. Just curious, Why
>> and where kicad is using it? And why and where kicad need
>> multi-threading?
>
> It's not multithreading, it's suspending a thread of work in the
> new tool code.
>
> Some thing like this: - Select a tool (suspend for a selection) -
> Other things happens, then user select a thing - (restart the tool
> coroutine) Check thing selected and so on
>
> The goal is *not* to use multiple cores or doing things in
> background; the idea is to stop inside a function and then resume
> from there when something desiderable happens.
>
I agree, the whole idea was to simplify event handling in the tool, so
instead of writing a complex state machine, you could just suspend the
execution of your tool code to wait for a matching event:
@Edwin: Coroutines are not a replacement for threads. They *aren't*
there for improving performance, just to simplify event handling in
complex state machines. For example:
case 1) - without coroutines - we need to code a (possibly large) FSM
by hand. This doesn't scale well in terms of code complexity,
especially if there are nested state machines .
void handle_event(event)
{
switch(state)
{
case state1:
if (event == event1) {
do something();
state = state2;
}
case state2:
if (event == event2) {
do_something();
state = state3;
}
case state3:
/// and so on
}
}
case 2) - with coroutines - we can execute our FSM in sequential code
and receive events using a wait() function, which yields the current
coroutine (i.e. transfers the control to the master event loop in case
of pcbnew) and wakes up the execution of the tool that called wait()
when a matching event arrives:
void my_tool()
{
wait(event1);
do_something();
wait(event2);
do_something_else();
}
All of the stack switching "magic" is hidden. You can find an example in
include/tool/examples/coroutine_example.cpp
Concerning boost::context, I see two options:
- get rid of the coroutines (i.e. rewrite all event loops/calls in the
GAL tools). Painful but doable, I would prefer to spend my time doing
something more productive (e.g. porting the remaining tools to GAL).
- turn boost::context into a single .cpp file library that one can
just add to the project and forget about it (think of ClipperLib as an
example).
As a side comment, I'm not surprised that boost devs insist on using
MASM under Windows - the syntax of the GNU assembler on x86/x86_64
platforms is just disgusting.
Tom
Follow ups
References
-
Re: KiCad Coroutines
From: Mark Roszko, 2016-01-04
-
Re: KiCad Coroutines
From: Torsten Hüter, 2016-01-04
-
Re: KiCad Coroutines
From: Mark Roszko, 2016-01-04
-
Re: KiCad Coroutines
From: Tomasz Wlostowski, 2016-01-06
-
Re: KiCad Coroutines
From: Wayne Stambaugh, 2016-01-06
-
Re: KiCad Coroutines
From: Torsten Hüter, 2016-01-07
-
Re: KiCad Coroutines
From: jp charras, 2016-01-07
-
Re: KiCad Coroutines
From: Lorenzo Marcantonio, 2016-01-07
-
Re: KiCad Coroutines
From: jp charras, 2016-01-07
-
Re: KiCad Coroutines
From: Mário Luzeiro, 2016-01-07
-
Re: KiCad Coroutines
From: Lorenzo Marcantonio, 2016-01-07