lua-users home
lua-l archive

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


On Wednesday 18 May 2005 5:01 am, Mukhsein Johari wrote:
> > hard threads/forks are the only way when the code you call takes a long
> > time without generating output.
>
> Hi,
>
> Well, the async twisted framework (python) does this, I think without
> resorting to threads/forks. From what I understand (not enough good
> docs) when you have a 'long running' call, you recode it to return
> immediately (so that it does not block) with a what they call a
> 'defered'. This has an attached callback that gets called when there's
> something sent back. You might want to investigate that:
> http://twistedmatrix.com/

if the 'long running' call isn't your own code you might not be able to 
'recode' it to make it fitting to a cooperative multitasking environment 
(like Copas)

the technique you describe is very similar to the Classic MacOS system calls: 
most of them had a 'sync' and 'async' version; the async take a callback to 
notify it has finished.

my 'helper threads' module does something similar, but to keep it simple for 
the user, it blocks the coroutine thread (yielding to other cothreads) while 
it's busy.

it's very easy to use:

-- normal Copas running code
...
...
helper.do (function()
     -- preemptively 'background' code
     ...
     ....
end)
-- normal copas code
...
...

but i run into some instabilities; when stress testing, the process died 
randomly at the thread destruction code.  since the thread library has to be 
compiled _into_ the Lua core, and there were some version mismatches, i 
figured it might be better to wait until we have a stable version 5.1... and 
hope LuaThreads works better then.

-- 
Javier

Attachment: pgp6DEDAWzy6d.pgp
Description: PGP signature