[Qt-interest] thread safety of Qt containers

Thiago Macieira thiago at kde.org
Mon Apr 26 11:41:07 CEST 2010


Em Segunda-feira 26 Abril 2010, às 11:26:17, Andre Somers escreveu:
> Hi,
> 
> I was wondering:
> Qt's documentation states that the methods in QList, QVector and QHash
> (and maybe QMap, I did not check) are reentrant. That means that they
> can be used in a thread, as long as the instance that is used is not the
> same, right?

Correct.

> So... how does QtConcurrent work? QtConcurrent::map() and the likes have
> multiple threads operating on data in the same container. How save is
> that? The docs say that only the non-in place operations make a copy of
> the container, so that would mean that multiple threads at the same time
> can write to a QList? They can't be using a QMutableListIterator though,
> as only one of those can be savely operating on a list at the same time...

There's a mutex. That ensures that there's only one thread accessing the 
container at a time.

> I am looking into QtConcurrent to speed up some heavy calculation work
> that I need to do. However, the amount of data is such that copying
> around data is really not an option. It is simply too much (datasets may
> range into the GB range).

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100426/4110a367/attachment.bin 


More information about the Qt-interest-old mailing list