[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [ANNOUNCE] luahttpd
- From: skaller <skaller@...>
- Date: 13 Jan 2005 00:33:30 +1100
On Wed, 2005-01-12 at 23:06, Javier Guerra wrote:
> it's similar to what i tried before using threads; but i kept stumbling with
> trying to read and write without blocking. at the end, i decided to use
There are several ways to solve this problem,
it isn't peculiar to Lua.
What you can do is replace the blocking operations
with a function that queues a message in an I/O request
queue, then you yield control to the scheduler.
You can do this in Lua by using a coroutine based scheduler.
One or more separate pre-emptive threads are used to service
the request queue -- either by doing blocking operations
or some other method. When a request is satisfied the
scheduler is notified, and it puts the coroutine making
the request back in the schedule list, eventually scheduling
it and passing the I/O request result to it (and removing
the request from the I/O queue).
[This is basically what Felix does, except it has a dedicated
instruction for control inverting blocking reads]
Another way to do this is make the bytecode interpreter
do the scheduling, in that case you'd be switching between
Lua state objects not coroutines, and you would be
doing the scheduling in C rather than in Lua -- say
you execute one bytecode from each running thread in turn,
and occasionally check if some 'blocked' thread can
be put back in the 'running' list by inspecting
the I/O service queue.
Both Python and Ocaml use this technique.
John Skaller, mailto:firstname.lastname@example.org
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net