lua-users home
lua-l archive

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


> > > To make sure the
> > > garbage collector does not collect stuff from suspended 
coroutines
> > > (including the one implicitly associated with main!) I have
> > to copy on
> > > coronew the entire content of the stack into the new stack.
> >
> > The stack is dynamic.  It will surely change after coronew.  So 
the
> > snapshot copied will not be valid very long.  And, the stacks of 
_all_
> > coroutines have to be marked by the gc.  Not only that of the 
current
> > coroutine and a snapshot of it's creator's stack.
> 
> Oh man... I did not think of that. And of course you are right. 
This is
> going to cause me a big headache. And changes in the Lua core, of 
course!
> 

Yeah, i didn't think of that myself. Although, i took a look at Lua's 
GC code and it seems simple enough to support multiple threads. 
Basicaly, you'd need to split up the marking and the collecting 
parts. Then simply call mark for all threads and then collect. It 
will require some changes to lua but at least it seems constrained to 
1 function. In my case it's somewhat easier since i set the gc limit 
so it doesn't do automatic collection. Since i'd be using this for 
video games, i don't want to have stalls due to gc at random points 
in time, so i'll do the gc manually when i feel it will not cause any 
speed issues (changing levels, opening up a menu, ...)

Sebastien St-Laurent