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

Konstantin Shegunov kshegunov at gmail.com
Fri Oct 27 23:04:29 CEST 2017


On Fri, Oct 27, 2017 at 7:43 PM, Elvis Stansvik <elvstone at gmail.com> wrote:
>
> The definition of reentrant that Qt's documentation uses is documented
> at http://doc.qt.io/qt-5/threads-reentrancy.html.
>
> It's a little different from the one used in for example the POSIX C API.
>

It's pretty much the same thing, just phrased in a different manner (the
latter being applied to the context of C).

Methods are stored in the static part of the binary and they are referring
to a class, not to an object. The object (i.e. the `this` pointer which
holds the reference to the memory) is local to the method, and is being
"injected" by the compiler into the method. Objects by themselves are
little more but a simple C struct. But before we venture into an academic
debate about it, let me say that the reentrancy issue here is a red
herring. It doesn't really matter. The only thing that matters is that a
specific class method guarantees that there will be no writes performed to
a memory location by declaring a method as non-mutable. It doesn't matter
if this memory location is global to the application or specific to an
object you only want to know that it does not write to the memory.

If you know that, which I knew is true for the containers because I'd
checked the code and had used that behavior numerous times, gives you the
ability to use the object from different threads provided you only use
`const` methods. And naturally, Thiago, confirms it's an intended behavior.


> but don't trust the const to always be an indicator of them being safe.


Which no one really claimed to be the case.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20171028/d4a2764d/attachment.html>


More information about the Interest mailing list