lua-users home
lua-l archive

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

Thanks to the talks at the Lua Workshop, I finally understood how I
could reimplement my scheduling algorithms without using a global
mutex. The gist is to use a central scheduler that does a single
"select" on all sockets and then to use coroutines to resume where the
calls would have blocked with blocking sockets.

Anyway, I want to use the dynamic nature of Lua to have a transparent
api that can be used with two different "polling" libraries (zmq/qt):

1. when used with zmq by using zmq.poll()
2. when used with Qt with app:exec()

>From my understanding, a zmq poll can work with non-zmq file
descriptors (zmq_pollitem->fd) and Qt can handle traditional sockets
with QSocketNotifier.

My plan now is to use zmq_poll when Qt is not running. When Qt dylib
is loaded, I would (in Lua):

1. move all zmq/traditional file descriptors to QSocketNotifier
2. use QTimer::singleShot for timed events
3. hand control to Qt with app:exec()

When events trigger QSocketNotifier, this calls the original
scheduling loop to resume the coroutine related to this socket/zmq

By reading Qt source code, QSocketNotifier just end up in a "select",
but I am not sure what happens with zmq (ZMQ_FD?)...

Is this totally insane ? Can it be done with Robert's zmq bindings
(which look really great) ?

Thanks for any comment,


[1] zmq --> Qt
[2] socket --> zmq
[3] ZMQ_FD