17

The Qt documentation states this about thread-safety and reentrancy:

Note: Qt classes are only documented as thread-safe if they are intended to be used by multiple threads. If a function is not marked as thread-safe or reentrant, it should not be used from different threads. If a class is not marked as thread-safe or reentrant then a specific instance of that class should not be accessed from different threads.

This seems to state that every function and class in Qt should be considered non-reentrant and non-thread-safe unless explicitly stated so.

However, in the documentation of QRect and QPoint, for example, neither thread-safety nor reentrancy is mentioned, but I find it hard to believe they are not. In fact, this old discussion says its a "lack" in the documentation:

These classes are just plain data (a few primitives), no shared structured or static data, so they are reentrant. That they are not marked as such, is a lack in our documentation.

So, how should we know if a function is reentrant or not? Is the reentrancy note omitted only for simple classes where it's implied by its obviousness?

3
  • 1
    Obvious or not, the docs are contradicting here. Might be worth filing a bug report.
    – thuga
    Mar 20, 2014 at 14:25
  • 1
    @thuga Done! I wonder if there's a way to compile a list of all classes that are missing the reentrancy note, to see if there are other obvious mistakes.
    – sashoalm
    Mar 20, 2014 at 14:41
  • QPointer seems to be one.
    – thuga
    Mar 20, 2014 at 14:45

1 Answer 1

2

I think the only safe answer to this question is to look at the source code. Clearly the Qt docs are not sufficient. Bugs should be filed with Qt for each undocumented reentrant class.

By Qt's definition of reentrancy, there are two criteria for determining if a Qt class is reentrant:

  1. It has no static data.
  2. It calls only reentrant functions and methods of other reentrant classes.

Accessing a singleton class would violate 2.

1
  • 1
    Or they should change the text to say that classes not marked reentrant might be either way :) They probably missed the point that unlike thread-safety, classes are reentrant almost by default.
    – sashoalm
    Apr 18, 2014 at 3:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.