> Sent: Friday, October 27, 2017 at 6:44 AM > From: "Konstantin Shegunov" <kshegu...@gmail.com> > On Fri, Oct 27, 2017 at 9:45 AM, Elvis Stansvik > <elvst...@gmail.com[mailto:elvst...@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. _______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest