[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Coroutines in Lua
- From: Edgar Toernig <froese@...>
- Date: Thu, 26 Oct 2000 02:58:31 +0200
Stefano Lanzavecchia wrote:
>
> What I have in mind is Python's microthreads. They are based on a small
> addition to the core (a timeslice parameter) which returns control to the
> registered coroutine handling the task switching (the coroutine is written
> in Python, Lua in our case) once the timeslice is expired (more or less).
> This is almost real pre-emptive...
... while within Lua. Sounds reasonable.
> ========================
> co1 = coronew("some_function")
>
> newvariable = 42 -- a very important constant!
>
> cororesume(co1) -- this causes GC to activate and eventually resume main
>
> print (newvariable) -- this will print NIL since when the stack for
> -- coroutine 1 was created, newvariable did not exist, therefore when GC
> -- started in coroutine 1 newvariable wasn't linked from any useful place.
> =========================
Hmm... Are you sure there's no other problem? This should work! The
global table is shared between all threads and shouldn't be affected.
And if you really have different L->gt the one of main should have been
freed. But then even finding 'print' would be pretty difficult ;)
Btw, when working on such things a debug malloc that fills freed memory
may be handy to detect references to stale data.
Ciao, ET.