[Qt-interest] do i need QReadWriteLock?
Malyushytsky, Alex
alex at wai.com
Fri Apr 17 23:10:16 CEST 2009
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.
In reality you normally have to handle a set of data which depends on each other or the value taken depends on the other conditions which may change.
And to make sure this value corresponds to such conditions you have to use blocking.
Also blocking is required when you handle complex data types, like arrays and classes.
But if you need to display a progress bar, this is not an issue.
So if you are sure that this variable still exists and don't have other dependancies, you don't have to do any blocking.
Regards,
Alex
-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Pascal Patry
Sent: Friday, April 17, 2009 8:19 AM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] do i need QReadWriteLock?
On Friday 17 April 2009 06:08:17 Serge wrote:
> Hi,
Hi Serge,
> i have 2 threads
> one is writing to bool value.
> another is only reading its value.
> they can do it simultaneously.
> must i use QReadWriteLock to block reading when writing happens, and
> block writing when reading happens? Or for bool value read/write from 2
> threads will not conflict?
Yes, you should always use proper semantics when dealing with threads.
Here, you should either use read/write locking functions or an atomic
operation.
> --
> Serge
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest
---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.
"This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you."
"Please consider our environment before printing this email."
More information about the Qt-interest-old
mailing list