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

Elvis Stansvik elvstone at gmail.com
Sat Oct 28 14:57:39 CEST 2017


2017-10-27 23:04 GMT+02:00 Konstantin Shegunov <kshegunov at gmail.com>:
> 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.

Alright, then I misunderstood. Sorry about that!

I didn't mean to start a debate at all, and agree with everything you said.

All I wanted to say was that the reentrant definition that Qt uses in
its docs does not guarantee that the const methods are safe to call on
the same instance from different threads (even if they likely are).
You'll have to turn to the code or to a trusted authority like Thiago
to ensure that they are.

Anyway, Jason solved his problem, so all is well :)

Best regards,
Elvis



More information about the Interest mailing list