Results 1 to 2 of 2

Thread: QPointer and thread safety

  1. #1
    Join Date
    Dec 2006
    Posts
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default QPointer and thread safety

    The Qt docs on QPointers don't specifically mention anything about thread safety. If used across multiple threads, do they somehow magically guarantee that the object doesn't get deleted between the check and the usage?
    Qt Code:
    1. if (p!=0)
    2. p->doSomething();
    To copy to clipboard, switch view to plain text mode 

    Looking at the source code it appears that they are not thread safe. True? If so, then I'll submit a sug to have the docs updated.

    -RobF

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPointer and thread safety

    What does the above have to do with thread-safety? First of all you are asking whether the operation is atomic not thread-safe and second of all these are two separate instructions with two separate calls to QPointer thus the thread can be interrupted somewhere inbetween the check and the call (so "if" is not atomic).

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.