lua-users home
lua-l archive

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


Just out of curiosity, has anyone here thought about what it would take to implement a preemptive scheduler in the lua core? Is that a good idea?


Javier Guerra wrote:
On Thursday 26 January 2006 12:58 am, Jon Smirl wrote:
keplerproject.org uses copas.  IIRC, you can create a copas socket that
wraps a luaSocket, but has the same interface (at least the same
interface needed after you wrap it).

If Copas doesn't actually do this, it would be extremely easy to add it
in.

it's in Copas, not Xavante itself. but the wrapped API is a small subset of luaSocket's, just what we needed for Xavante. (but it's very easy to extend it)

Wrapping of blocking functions is key to how Ruby implements threads.
Green threads don't work if an application thread can get stuck in a
blocking system call. By wrapping everything in the run-time Ruby
makes sure you can't get stuck.

sounds a nice feature; but there's one point most people seems to be missing: Lua has no real threads (green or whatever). Coroutines are not threads.

of course, given the power (coroutines), we build the mechanism (threads); that's what Copas is about. it works, but it's far from a really complete threading mechanism.

i've glanced around Diego's dispatch.lua (in the latest LuaSocket); and it seems to be far simpler and cleaner than Copas. at least, the wrapped API is much closer to the full LuaSocket API.

but i feel that most of us wouldn't like to get a wrapping mechanism written in stone (in the language itself). much like there's no fixed and standard OO system in Lua. (of course, from time to time someone asks for one... but most of us just implement one when needed)

what i'd like to see is the LuaSocket dispatch system extended a bit more, to make it very easy for other module writers to create non-blocking calls that cooperate with the dispatch. that way, we would have a de-facto threading (and wrapping) system.

also, i'd like to see non-blocking file IO (and database, and process spawning, and...) all pluggable into dispatch.lua