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.

    Thanks
    Montez

  2. #2
    Join Date
    Jul 2012
    Posts
    244
    Thanks
    27
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: moveToThread not thread-safe

    Documentation:
    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.
    Montez

Similar Threads

  1. Replies: 1
    Last Post: 25th October 2012, 20:47
  2. Replies: 11
    Last Post: 12th September 2012, 17:25
  3. Replies: 1
    Last Post: 4th September 2012, 15:13
  4. Replies: 5
    Last Post: 7th February 2012, 23:13
  5. thread-safe
    By babymonsta in forum Qt Programming
    Replies: 0
    Last Post: 5th May 2010, 11:18

Bookmarks

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.