[Qt-interest] thread safety of Qt containers

Andre Somers andre at familiesomers.nl
Mon Apr 26 11:26:17 CEST 2010


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?

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...

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).

André




More information about the Qt-interest-old mailing list