lua-users home
lua-l archive

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


On Mon, Mar 31, 2008 at 12:51 PM, Eugen-Andrei Gavriloaie
<shiretu@gmail.com> wrote:

> No, I don't want to use multiple threads. Only for time consuming functions.
> But those functions will not have anything to do with Lua. In fact, all the
> server is single threaded (accepting connections, serialize/deserialize
> messages, invoking Lua function upon messages receive, etc). If one user
> wants to have access to the database, he will put a message in a special
> queue. The working threads will pick the work load from there, process it
> and put the results in another queue. last operation that a thread is doing
> is to signal "job completed" to the main thread who in turn picks up the
> result from the queue and do whatever there is to do with it. Including
> resume a yielded lua_State. So, the Lua script writer doesn't have to know
> anything about the internals of the database layer. All he has to know is
> the type and connecting string to the database. And, of course, to write the
> SQL in that particular dialect of SQL.

that's exactly the model of the Helper Threads Toolkit (HTT) referred
by Graham.  the biggest difference is that it lets you write your main
program in Lua, and just write C functions for those time-consuming
tasks (or blocking APIs, like DB access). HTT would let you put task
objects in queues and spawn/pool helper threads (or working threads)
to execute the tasks.

included in the toolkit is a very simple (but enough for most cases)
Lua scheduler, uses coroutines for the Lua 'threads' and queues tasks
for the helper threads.

-- 
Javier