[Qt-interest] FW: ASSERT failure in QMutex::unlock(): "A mutex must be unlocked in the same thread that locked it."

Thiago Macieira thiago at kde.org
Sun Jul 18 13:39:04 CEST 2010


On Sunday 18. July 2010 08.27.51 Sarvesh Saran wrote:
> My main purpose behind exploring QThreads is that my application connects
> to multiple servers, receives messages and does a lot of message
> processing for each message.
> 
> I would like to create threads to handle this, one for each server. Each
> QThread would connect to a server, receive streaming messages, parse them
> and simply send an update to the Main Thread  ( which will use these
> updates to populate a QTreeWidget). Because each server sends a lot of
> messages it makes sense to have a separate thread handling the server.

Hello

Threads don't connect to servers. Sockets and other IPC mechanisms do.

This may sound pedantic, but it's the core of the issue that you're facing. 
I'd like you to understand the distinction.

QThread is a class that wraps and controls an operating system thread. Do not 
use it for any other purposes. Your mistake is to mix the two things and put 
your working code (more importantly, your signals and slots) in the class you 
derived from QThread.

Instead, create a separate class that it is your code / job and assign it to a 
thread. QtConcurrent can even help you here by use of QtConcurrent::run(). 
Also make sure that this object's affinity, if it derives from QObject, is with 
the thread in question. You do that either by creating it inside the run() 
function, which is the easiest, or by using moveToThread().

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100718/7d22581f/attachment.bin 


More information about the Qt-interest-old mailing list