Qt documentation and reentrancy
Asked Answered
C

1

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?

Courtenay answered 20/3, 2014 at 13:52 Comment(3)
Obvious or not, the docs are contradicting here. Might be worth filing a bug report.Clemmy
@Clemmy 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.Courtenay
QPointer seems to be one.Clemmy
F
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.

Falster answered 17/4, 2014 at 23:24 Comment(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.Courtenay

© 2022 - 2024 — McMap. All rights reserved.