lua-users home
lua-l archive

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


Hi Everyone,
I am looking for an elegant solution for the following problem.
Let say, I have a Lua or C function foo() that is called from my main
application written in Lua. When called, foo() acquires some
resources, waits on some locks, opens and closes network connection,
etc. What exactly foo() does is not really important. What is
important is that foo() acquires resources and take UNPREDICTABLE time
to return. The nature of the main program is such that if foo() does
not return in, let say, 5 seconds (wall clock time) the main program
abandons foo(), releases back all the resources foo() has acquired and
moves on to something else (plan B).

Based on this description I would like to implement the following
behaviour in Lua:
1: Set an expiration timer
2: When timer gos off
   2.1: Stop executing foo()
   2.2: Call some function that cleans up the resources acquired by
foo() and return foo() error code
   2.3: move on

I am not sure that this can be achieved in Lua at all. After all, Lua
does not have preemptive multitasking. But I hope that with  a help of
some Lua extensions (multi-threading and friends) an elegant solution
can be found.

Any help is highly appreciated.

--Leo--