[Interest] QImage::copy threadsafe?
Giuseppe D'Angelo
giuseppe.dangelo at kdab.com
Sat Nov 9 18:12:26 CET 2019
Hi,
On 08/11/2019 18:33, maitai wrote:
> All is in the tile, is QImage::copy threadsafe? The method is const but
> is it enough? Documentation does not state it is thread safe so I am
> wondering.
>
> My case is I have a QImage loaded in the main thread, and many many
> threads that keep extracting small rectangles from it using
> QImage::copy. No other operations occur on the QImage once loaded.
The short story is that const methods on Qt value classes are generally
thread safe. The exceptions are very very few (e.g. QString::utf16).
I don't believe this is guaranteed anywhere in the documentation,
though. If you can live with the "implementation guarantee" then, by all
means, just use copy() from multiple threads.
On the other hand, you could just create copies of the image and give
them out to each worker thread. Copying a QImage is very cheap (it's
implicitly shared so it won't deep copy the data anyhow).
HTH,
--
Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4329 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20191109/ec982fb1/attachment.bin>
More information about the Interest
mailing list