[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: First timer on cooperative multitasking
- From: Josh Simmons <simmons.44@...>
- Date: Sun, 28 Aug 2011 08:12:21 +1000
On Sat, Aug 27, 2011 at 6:50 PM, Thijs Schreijer
<thijs@thijsschreijer.nl> wrote:
> Hi all,
>
>
>
> I’ve been using lua for some time as an embedded scripting language. The
> implementation was a pre-emptive multitasking environment. I now have the
> intention to do some lua-only developments and have been looking into the
> cooperative multitasking model.
>
>
>
> The basics are very clear, but there is one part that I feel uncomfortable
> with; How often and when would I have to yield? Are there any guidelines on
> that?
>
>
>
> In general my understanding is that not yielding for too long, will make
> other threads unresponsive, that’s obvious. But I intent do use luasockets
> and maybe some RS232 serial stuff, so that’s where my concerns are; loosing
> incoming data on those IO channels because another thread doesn’t yield in
> time.
>
>
>
> The google mainly returned long debates on preemptive vs cooperative, but no
> info on how to make it work best.
>
>
>
> So; where do I need to look for this info? And hints/tips? Thx for your
> help!
>
>
>
> Regards,
>
> Thijs
It more depends on your application architecture than anything.
It's easy where you're IO driven, yield to the scheduler whenever you
are at a point you need to wait for IO. Provided you don't get locked
up in IO handling this async model works well.
There are some examples in the PiL section on coroutines
http://www.lua.org/pil/9.html