lua-users home
lua-l archive

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


Hi Greg,

I specifically wrote “darksidesync” for this purpose. At the time to create a binding to LibUPnP. It does the exact same thing, it starts background threads for listening and all callbacks are on those background threads.

The main premise is that the main-application loop is on the Lua side, while the C lib runs the background threads and generates the call-backs

It’s been a while since I visited that code though.

Code is here: https://github.com/Tieske/DarkSideSync

Thijs

On 22 Dec 2017, at 01:23, Gregg Reynolds <dev@mobileink.com> wrote:

Hi folks,

Thinking about writing a Lua binding for https://www.iotivity.org over the holidays. What could be more fun?

But I'm a little worried about threading. Using the lib involves callbacks, each of which is on a separate thread. I.e. you pass a cb to the send fn, and the engine, when it receives a response, passes control to the call back, with the incoming msg as an arg, but on a new thread.

My understanding is that I would just need to create a new Lua state for each thread, to pass to the call back.

Seems reasonable to me, but it also looks like one of those things that turn out to be much more complicated than they seem. For example, if the same callback can occur multiple times, can I save one Lua state per callback and reuse it? And what if I want to share some data across threads?

Any examples of this sorta thing out there? Any guidance appreciated.

Gregg