lua-users home
lua-l archive

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


Hi Lua-list,

On Thursday 31 July 2008 20:42:32 Asko Kauppi wrote:
> 
> When/if the green threads becomes a true possibility in Lua, would it  
> mean that the code run within them is not allowed to touch the  
> 'coroutine.*' features itself?
Looks like coroutines would work normally along with green threads. Have not tried this yet but I don't see any reasons why they would not work.


I want to inform that I made a simple implementation of green threads for Lua as a part of my hobby project:
http://code.google.com/p/luame/
(This will be a Lua framework for Symbian OS).

I made a new function similar to existing lua_resume() but which takes additional argument - number of bytecode instructions to execute before yield:
lua_resume_ninstr(). I also added a new variable to lua_State structure which counts the instructions before yielding. I also had to modify luaV_execute() to check if it is time to yield.
For those who interested:
all changes I made to lua core are labeled with
	/* added by igagis@gmail.com */
comment, so it will be easy to locate all the changes.

And finally, I wrote a simple scheduler which executes 10 instructions per thread.
And it looks like working.

This approach still lacks from yielding-from-within-the-iterator problem, but it looks like a simple patch will fix this, just had no time to implement it yet.
(the idea is simple, detect when we enter the iterator function and forbid yielding until leave the iterator function).
And it is also forbidden to call lua programs via lua_pcall() from within the lua C functions, so lua C functions should not call lua_pcall() etc. Thus some of the functions from Lua base lib will not work (like load() lua function which uses a "loader" callback function).

Thanks,
Ivan