Qt documentation and reentrancy

筅森魡賤 提交于 2019-12-06 17:12:44

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/22535094/qt-documentation-and-reentrancy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!