lua-users home
lua-l archive

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


On Sunday 10, Tomas Guisasola Gorham wrote:
>  	Hi Robert
> 
> > lua-llthreads [1] is a Low-Level native threads module for Lua.  This
> > module is designed to be a simple wrapper for creating threads from Lua.
> >  Each native thread has it's own lua_State object and shares nothing
> > with it's parent thread (the thread that created it).  The module only
> > allows parameters to be passed to the child thread when it is created
> > and returned from the child thread to the parent thread only when the
> > parent joins the child thread and the child thread exits.
> 
>  	Preemptive multitasking without memory sharing?  It is similar
> to processes, but within the same OS process, right?

Yes, this is Preemptive multitasking with no shared state.  The parent thread 
can join with non-detached child threads, to get the return values from the 
child threads.  This is easier to do then forking a lot of child processes, 
waiting for them to finish, then parsing there output.

I wouldn't normally use this module without ZeroMQ or a sockets library to 
provide communication between the parent threads and the child threads.  But 
for really simple background worker threads, it could be used stand-alone 
without a IPC library.

For projects that already use LuaSockets and need a pool of worker threads to 
handle some blocking work (i.e. long database query, image processing), then 
it would be easy to bind a server socket to 127.0.0.1 in the parent thread, 
and then spawn a pool of worker threads that connect to the server socket to 
get work from the parent thread.

-- 
Robert G. Jakabosky