[Qt-interest] Qt4.4.3 paintEvent thread-safe

Oliver.Knoll at comit.ch Oliver.Knoll at comit.ch
Wed Dec 24 13:00:37 CET 2008


Thiago Macieira wrote on Wednesday, December 24, 2008 12:02 PM:

>> ...
>> does not copy the actual pixel data (yet - only as soon as the
>> "copiedImage" is actually modified later on). And this IMHO means
>> that simply "copying" a QImage (or any other implicitly shared data
>> structure) like this does not prevent concurrent access to the pixel
>> data ...
> Hi Oliver
>
> The above code is *supposed* to work just fine. The Qt classes that
> do implicit sharing also do atomic copy-on-write detaching.

Hi Thiago,

My above statement was off course non-sense, as I just found out after another 10 minutes "deep thinking" (am I the only person who reads his emails *after* having sent them? ;)

It was just my natural instinct "Attention!" reaction when reading about "implicit sharing", "threads" and "just copy your data and you don't need to worry about concurrent access" (and Qt always "surprises" me how practically designed it is and that "things just work" ;).

> When it encounters a QueuedConnection or if the target object in
> an AutoConnection is in a different thread, it will do a copy of the
> arguments, just like you did at the top of this message.
> So that copy is unnecessary.

Oh, that's nice, too, I wasn't aware of this implicit copy mechanism. So my other comment ("Copy the data in the thread that owns it") becomes also void. :)

Happy Xmas and New Year!
  Oliver
--
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22




More information about the Qt-interest-old mailing list