[Qt-interest] do i need QReadWriteLock?
Thiago Macieira
thiago.macieira at trolltech.com
Sat Apr 18 00:05:35 CEST 2009
Malyushytsky, Alex wrote:
>I believe for standard types you don't need lock anything cause these
> operations are atomic, which is guaranteed by the system and is much
> more efficient than any other blocking you can create.
>
>In other words you don't have to worry that 1 process will change half
> of the bits and another will read a complete garbage.
That's only correct for the type sig_atomic_t, but it happens to be
correct as well for all platforms Qt supports.
Note, however, that you have to declare your type as "volatile" if you
want to see the write that another thread made. Otherwise you may never
see the change in the value.
This loop, for example, has only two conditions: either it runs 0 times,
or it runs forever.
bool quit;
void MyThread::run()
{
int i;
while (!quit)
++i;
}
Regardless of whether quit is modified by another thread or not.
--
Thiago Macieira - thiago.macieira (AT) nokia.com
Senior Product Manager - Nokia, Qt Software
Sandakerveien 116, NO-0402 Oslo, Norway
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090418/51e11709/attachment.bin
More information about the Qt-interest-old
mailing list