Results 1 to 3 of 3

Thread: moveToThread not thread-safe

  1. #1

    Default moveToThread not thread-safe

    Hi all,

    I'm working in a library where objects are created and moved to a specific thread (global reference). The library must support multi threading this means that different objects can be created simultaneously and moved to this global thread instance.
    Do I need to have a lock to protect my global thread when moving those objects?

    I understand that moveToThread is not thread-safe if trying to move the same object but how about the thread instance.


  2. #2
    Join Date
    Jul 2012
    Thanked 14 Times in 13 Posts
    Qt products

    Default Re: moveToThread not thread-safe

    Warning: This function is not thread-safe; the current thread must be same as the current thread affinity. In other words, this function can only "push" an object from the current thread to another thread, it cannot "pull" an object from any arbitrary thread to the current thread.

    So as long as the thread calling x.moveToThread(global_thread) is the same thread that created (or rather, currently owns) the object you are fine.

  3. #3

    Default Re: moveToThread not thread-safe

    This is great!
    Thx a lot for your reply.

Similar Threads

  1. Replies: 1
    Last Post: 25th October 2012, 19:47
  2. Replies: 11
    Last Post: 12th September 2012, 16:25
  3. Replies: 1
    Last Post: 4th September 2012, 14:13
  4. Replies: 5
    Last Post: 7th February 2012, 22:13
  5. thread-safe
    By babymonsta in forum Qt Programming
    Replies: 0
    Last Post: 5th May 2010, 10:18


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.