lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I wonder what exactly you're hoping to gain from making the yields implicit?

It just means that now you have to deal with the synchronisation problems that stem from your code being potentially interrupted at any point while you don't pick up the real parallelism from OS pre-emptive threading primitives.


On Fri, Mar 29, 2013 at 5:02 PM, Leo Romanoff <romixlev@yahoo.com> wrote:




----- Ursprüngliche Message -----
> Von: Ross Bencina <rossb-lists@audiomulch.com>
> An: Lua mailing list <lua-l@lists.lua.org>
> CC:
> Gesendet: 4:58 Freitag, 29.März 2013
> Betreff: Re: Lua and preemptive scheduling for coroutines
>
> On 29/03/2013 2:35 PM, Tim Hill wrote:
>>  You're not going to be able to pull that one off. The fundamental
>>  structure of coroutines is different from threads, and nothing you do
>>  can really change that (aside from a VERY significant reworking of
>>  the Lua code base).
>
> I don't know about that, all he's talking about is conditionally
> injecting yeild() into the code at arbitrary points (such as the end of each
> statement)
>
> This could be done manually with a syntactic substitution. The question is
> whether it can be done using a debug hook or similar mechanism.


That's a correct guess and interpretation. I've done something similar for Java using a byte-code instrumentation during class-loading. Indeed, I was injecting a conditional yield() after each n instructions. Alternatively, it could be done at the beginning of each basic block in the control-flow graph of a function. I know that Groovy language, which is also Java based, does something very similar.

But I have no idea how something like byte-code rewriting can be done in Lua. And I have a feeling that debug hooks are a more light-weight approach. They don't need to really change the code by rewriting it. They just intercept execution after each instruction, line, call, return, etc, which seems to be a cleaner way.

Another important point: In case of instruction counting or time slices, I don't need to suspend exactly when the even happens, i.e. I don't need to suspend e.g. inside a C stack (or Lua stack) frames and so on. It is OK to suspend a bit later, once it is safe, i.e. when the execution is easy to suspend.

-Leo