lua-users home
lua-l archive

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


On Tuesday 23 November 2004 02:23, Mark Hamburg wrote:
[...]
> That being said, a good basic scheduler and I/O package for Lua would
> probably be a good thing.

I have a couple of server applications written in C++ that I'm doing slow 
development on, that use coroutines extensively to manage incoming 
connections. Coroutines are absolutely *magic* for this kind of thing.

<plug>http://spey.sourceforge.net</plug>

However, the thing I've come to realise is that as your program gets more 
complicated, your coroutine scheduling has to get more complex, and it's not 
long before you need a fully-fledged scheduler. Spey's scheduler is pretty 
simple, but my other application has a proper round-robin scheduler with 
timer support, etc.

So, basically, I think a standard scheduler for Lua would be a really good 
idea, preferably with a set of standardised hooks for I/O libraries to hook 
into. I've found that the set of primitives largely boils down to

* wake me up no later than <n> usecs from now
* wake me up if fd <f> becomes readable/writable/exceptional, or something 
else happens
* go to sleep
* wake up thread <t>

You can pretty much do everything with these. Your I/O routines end up being 
along the lines of:

while data still to read
 attempt read
 if data available
  read it
 else
  wake me up when data becomes available
  go to sleep

However, I'm not sure that the Lua I/O model does asynchronous I/O terribly 
well; it's not something I've really looked at. I'm not sure of the best way 
of mapping this to Lua.

-- 
+- David Given --McQ-+ "...it's not that well-designed GUI's are rare,
|  dg@cowlark.com    | it's just that the three-armed users GUI's are
| (dg@tao-group.com) | designed for are rare." --- Mike Uhl on a.f.c
+- www.cowlark.com --+