Making the C library thread-safe is giong to be quite an undertaking, potentially requiring a ton of re-design work and changing a good number of the APIs (particularly if reentrance is something we want).
As far as having C++ stop spawning threads, they are quite required unfortunately. Unless we want our customers to be required to run the message pump, we need a thread to continuously call OCProcess. Removing the threads spawned upon message retrieval wouldn't be that big of a deal, however it would cause a few problems. Note that each of these is called in the C-context, so it would result in user-code freezing the message pump and likely introducing a number of delays in message receiving. I am curious in what way you find the C++ implementation to not be thread safe? It should be safe to call the C++ implementation from a number of threads, and we have an example that does just that. On Tue, 2015-02-17 at 11:05 -0800, Thiago Macieira wrote: > Hello all > > Short story: > > Another team inside Intel was trying the IoTivity library and one of the > feedback items they gave to me was that the library is "threadful but not > thread-safe". I did a little investigation and asked some people some > questions and it seems they are right. That seems to me like a recipe for > disaster, so how soon are we addressing this? > > Long story: > > Looks like the C library is meant to work without threads, since it may be > used on devices without support for threads. From all I can tell, this > library > is not thread-safe: only one thread can access the resources of the library > at > a time. > > In turn, the C++ library implements threading, by spawning threads in the > background to do the actual socket work and do callbacks. That's why some of > our examples have a while (true) sleep(5); for main function, which is quite > unusual to say the least. The problem here is that, despite using threads, > the > C++ library is *not* thread-safe. That means you can still not use it from > threads you started yourself. > > I don't know why this came to be, but my guess is that using threads was the > easiest way to integrate with external main loops (i.e., we don't have to) > and > use blocking calls on the sockets. > > The consequence is that it will be very hard for libraries to use the > IoTivity > library to wrap and provide services, since the resources are supposed to be > unique in the application. It will also be very hard to integrate with > applications that use threads from other frameworks, since the developer will > have to figure out how to call back into the right threads before calling to > IoTivity code. This severely limits the usability of our libraries. > > I'd like to request we make the C library thread-safe and that we stop > spawning threads in the C++ library. I know this is open heart surgery, but I > think it's needed. > > How soon could we do this? >
