[Interest] QMap crash when using QtConcurrent::blockingMapped()

Jason H jhihn at gmx.com
Fri Oct 27 15:52:30 CEST 2017


> Sent: Friday, October 27, 2017 at 6:44 AM
> From: "Konstantin Shegunov" <kshegunov at gmail.com>
> On Fri, Oct 27, 2017 at 9:45 AM, Elvis Stansvik <elvstone at gmail.com[mailto:elvstone at gmail.com]> wrote:

> > QMap isn't thread safe, so I don't think your use is guaranteed to be safe, even if you're only reading.
 
> You're right, in the formal sense of the word, but if there are no `mutable` members or `const_cast` usage a reentrant class can be used from different threads IF the calls are read-only. I sometimes use `QHash` like this where I need to read from a pre-populated hash from different threads, with the understanding there's no need to lock something if the memory is never changed.


I think that is the operative definition of "reentrant"? "Thread-safe" would imply mean that any mutating operations would succeed and leave things in a consistent state, usually via mutex. Reentrant would imply the same function can be called in an overlapping manner. Reentrant and thread safe means that both are true. The QMap documentation explicitly states that it is not thread safe, but it is reentrant. Which is how I am using it and why I posted. Where I did mess up is in using non-const [] which can cause mutations, though it's use in my situation did not need to, so I did not expect it to, but it did anyway. :shrug:

So getting back to your statement "I don't think your use is guaranteed to be safe, even if you're only reading." I think *is* guaranteed to be safe by the documentation, as long as I use it correctly. Anyway, just wanted to point that out if you missed it in the docs. :-) Knowing it's reentrant can be a big help.



More information about the Interest mailing list