lua-users home
lua-l archive

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


Title: Message
Hi all,
 
I just (re-)discovered LUA and I must say I'm impressed with LUA 5.0. It's fast and has some nice new language constructs. I'm currently evaluating it to be used in embedded systems.
 
For that, I realy need some kind of concurrent processes. The coroutines look nice, but - having worked with such co-operative systems in the past -
I'd rather not rely on a process to be 'friendly' enough to do a 'yield'
from time to time. I'm currently looking at 'hot plugable code' - to be
read from the network - and in that case it is almoust for sure that - one day - one of the processes will hang up the complete system.
 
I don't need full fledged 'threads' because that probably would involve using the threads of the underlying OS. In my case, that would imply the installation of an OS on my embedded system and that's something I would like to avoid.
 
I would be happy with a version of 'coroutine.resume' that can time-out.
 
That way, I could e.g. write my own scheduler.
 
Is there anybody who already did do something like that?
 
Or - the other way around - would somebody else be interested in that?
 
As a test I fooled around in the VM and hacked a bit around to see if such a construct is at all possible. I added a primitive called 'coroutine.timedresume' that behaves as the 'coroutine.resume' but takes as it's second parameter a number which represents the milliseconds after which a 'yield' should be 'forced'. Of course, there is no result yet if this happens. It can be 'intermixed' with the normal 'coroutine.resume' and the 'coroutine.yield'.
 
As an example, this is a transcript of one of my tests.
 
== >
== >
== > function fib(n)
== >>   if n<2 then
== >>     return n
== >>   else
== >>     return fib(n-1)+fib(n-2)
== >>   end
== >> end
== >
== > co = coroutine.create(fib)
== >
== > s, v = coroutine.timedresume(co, 4000, 35);
== > print(s,v)
== true    nil
== > s, v = coroutine.timedresume(co, 4000);
== > print(s,v)
== true    nil
== > s, v = coroutine.timedresume(co, 4000);
== > print(s,v)
== true    9227465
== > s, v = coroutine.timedresume(co, 4000);
== > print(s,v)
== false   cannot resume dead coroutine
== >
== >
 
This is the kind of behaviour I'm looking for.
 
Is there already something like this out there?
Or, should I take some more time in getting my implementation correct?
Or, should I do something completely different?
 
Wilfried Verachtert

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.644 / Virus Database: 412 - Release Date: 3/26/2004