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?

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center

Reply via email to