lua-users home
lua-l archive

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


Hello,

I've be using coroutine and write a dispatcher to a server program
written by lua. The basic idea (psudo code) is like this:

repeat
    for i=#threads,1,-1 do resume thread[i] and check the result
    end
    if all threads are yield by socket timeout, then do socket.select
for all socket
    end
until #threads == 0

the thread itself will handle the global table, which stores all
pending socket for socket.select()

Now I want to add timer feature, so that threads can suspend for a
specific time and then resume.

The problem is that timer threads are not yielded by a socket timeout,
so socket.select does not work for timer. When I do socket.select and
any timer expires, select() still blocks.

Is it possible that the select() works both for socket and timer? or
is there any good practise to dispatch both threads yield by socket
timeout and those who yield by timer like sleep()?

Thanks.