PDA

View Full Version : QPointer and thread safety



Nb2Qt
22nd August 2008, 09:09
The Qt docs on QPointers (http://doc.trolltech.com/4.4/qpointer.html) 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?


if (p!=0)
p->doSomething();


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

wysota
22nd August 2008, 09:22
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).