lua-users home
lua-l archive

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


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