Qt World Summit: Register Today!

Destruction in separate threads

  • Situation 1

    Let's assume we have two threads (thread1 and thread2), each running their own event loop hosting a single QObject (obj1 and obj2). The signals of the two QObjects are connected to slots on the alternate object, and aside from this signal-slot communication, the two objects do not access each other directly.

    Is it safe if obj2 is destroyed, without disconnecting it from obj1 first, while obj1 continues to execute in its own thread?
    Is there any way that obj1 might hit some race condition where it sends a signal to obj2 before obj2 can disconnect itself?

    Keep in mind: In my hypothetical case, the thread2 message loop is being shut down immediately following the obj2 destruction, so any lingering obj2 messages shouldn't be a problem (otherwise, I would use deleteLater()).

    Situation 2

    If a deleteLater signal is put into the message loop, but the message loop is then immediately exit()ed, is the object ever deleted? If it isn't, is this a bug? It seems that deleteLater's should always be processed, even if a thread is closing.

Log in to reply