lua-users home
lua-l archive

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


Maybe this is a red herring to even bring up, but are Dunkel's protothreads a possible portable solution to some of lua's woes with coroutines?

http://www.sics.se/~adam/pt/

I'm not in a position right now to give a technical analysis of this, but wanted to make sure everyone was aware of this tool.

Regardsm

-joe

On Sun, Jan 18, 2009 at 11:42 AM, Tobias Markmann <tmarkmann@googlemail.com> wrote:
On Sun, Jan 18, 2009 at 3:55 PM, Mike Pall <mikelu-0901@mike.de> wrote:
Tobias Markmann wrote:
> > attempt to yield across metamethod/C-call boundary
> > stack traceback:
> >     [C]: in function 'wait'
> I thought with the coro patch from luajit.org something like this is
> possible. So my question is: How to yield/resume the right way from C?

Three possible causes:
- Either you're attempting to yield from the main thread
 (this doesn't work, it must be a coroutine)
- or you're not using coroutine.resume/lua_resume() to run your
 coroutines
- or you're creating the coroutine with lua_newthread() from C.

Yielding across C frames only works if you create the coroutine
with a C stack. So either use coroutine.create/coroutine.wrap from
Lua or use lua_newcthread() (note the 'c') from C.

Your use of lua_yield() is perfectly fine in the context of Coco.
The docs are here: http://luajit.org/coco_api.html

--Mike

Yeah...that took the job. Using lua_newcthread() now but running in other problems now. Without any calling of my function that is yielding i get EXC_BAD_ACCESS if i try to execute my lua script which ran nice before using lua_newcthread() instead of lua_newthread().

Here is some piece of backtrace and i'm running all that stuff on an intel mac.
(gdb) bt
#0  0x003c059c in matchl ()
#1  0x00019163 in luaD_precall () at LuaThread.cpp:482
#2  0x00024761 in luaV_execute () at LuaThread.cpp:482
#3  0x000195a0 in luaD_call () at LuaThread.cpp:482
#4  0x00014fc3 in lua_call () at LuaThread.cpp:482
#5  0x003bf789 in pushcapture ()
#6  0x003bf658 in pushcapture ()
#7  0x003bfbdb in pushallvalues ()
#8  0x003bf76c in pushcapture ()
#9  0x003c08e5 in matchl ()
#10 0x00019163 in luaD_precall () at LuaThread.cpp:482
#11 0x00024761 in luaV_execute () at LuaThread.cpp:482
#12 0x000195a0 in luaD_call () at LuaThread.cpp:482
#13 0x00014fc3 in lua_call () at LuaThread.cpp:482
#14 0x003bf789 in pushcapture ()
#15 0x003bf658 in pushcapture ()
#16 0x003bfbdb in pushallvalues ()
#17 0x003bf76c in pushcapture ()
#18 0x003c08e5 in matchl ()
#19 0x00019163 in luaD_precall () at LuaThread.cpp:482
#20 0x00024761 in luaV_execute () at LuaThread.cpp:482
#21 0x000195a0 in luaD_call () at LuaThread.cpp:482
#22 0x00014fc3 in lua_call () at LuaThread.cpp:482
#23 0x003bf789 in pushcapture ()
#24 0x003c08e5 in matchl ()
#25 0x00019163 in luaD_precall () at LuaThread.cpp:482
#26 0x0002469e in luaV_execute () at LuaThread.cpp:482
#27 0x000195a0 in luaD_call () at LuaThread.cpp:482
#28 0x00014fc3 in lua_call () at LuaThread.cpp:482
#29 0x003bf789 in pushcapture ()
#30 0x003bf658 in pushcapture ()
#31 0x003bfbdb in pushallvalues ()
#32 0x003bf76c in pushcapture ()
#33 0x003c08e5 in matchl ()
#34 0x00019163 in luaD_precall () at LuaThread.cpp:482
#35 0x00024761 in luaV_execute () at LuaThread.cpp:482
#36 0x000195a0 in luaD_call () at LuaThread.cpp:482
#37 0x00015011 in f_call () at LuaThread.cpp:482
#38 0x00018a8b in luaD_rawrunprotected () at LuaThread.cpp:482
#39 0x00019892 in luaD_pcall () at LuaThread.cpp:482
#40 0x00015085 in lua_pcall () at LuaThread.cpp:482
#41 0x0000a068 in LuaThread::onRequest_coro (L=0x143f58) at LuaThread.cpp:178
#42 0x00019163 in luaD_precall () at LuaThreadExecuter.cpp:20
#43 0x00024d51 in coco_start () at LuaThreadExecuter.cpp:20
#44 0x00018a8b in luaD_rawrunprotected () at LuaThreadExecuter.cpp:20
#45 0x00025021 in coco_main () at LuaThreadExecuter.cpp:20

I hope you can give me a hint what is going wrong there. It worked before using coro's lua_newcthread, which i'm calling with a stack depth of zero because according to documentation that way it takes the default size.

Cheers,
Tobias