[Interest] Is QLocalSocket reentrant?

Thiago Macieira thiago.macieira at intel.com
Fri May 22 18:40:24 CEST 2015


On Friday 22 May 2015 14:35:05 Calogero Mauceri wrote:
> Hi all,
> 
> sorry if this is a stupid question, but I'm having some weird memory
> corruption problems when using QLocalSocket in multiple threads.

It follows the same as all other QObject classes: they are reentrant if you 
operate on different objects and each object must only be used in the thread 
they are associated with (moveToThread).

> I have a server process, accepting connections from client processes
> through a QLocalServer instance. Every time a new connection is accepted
> by the QLocalServer, the server launches a thread that communicates with
> the client through the QLocalSocket.
> 
> The code I'm using to launch the threads in the server is something like
> this
[cut]
> Each thread is using its own localSocket to communicate with the client.
> 
> My question is, is it safe to use different instances of QLocalSocket
> from different threads without guarding those sockets? The documentation

Yes.

> does not report QLocalSocket is reentrant. What does it imply? Should I
> guard all QLocalSocket instances with a global mutex before using them?

It implies that it's the default setting for all classes.

Put some debugging information in your MyWorker slots and check that they are 
being run in the thread you wanted them to be run in.

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




More information about the Interest mailing list