[Interest] QImage::copy threadsafe?
giuseppe.dangelo at kdab.com
Sat Nov 9 18:12:26 CET 2019
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
> 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).
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...
Size: 4329 bytes
Desc: S/MIME Cryptographic Signature
More information about the Interest