Qt文档和重入 [英] Qt documentation and reentrancy

查看:146
本文介绍了Qt文档和重入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Qt文档说明了有关线程安全和重入的问题: / p>


注意:如果想要由多个线程使用,Qt类只记录为线程安全。如果一个函数没有标记为线程安全或可重入,它不应该从不同的线程使用。如果一个类没有标记为线程安全或可重入,那么该类的特定实例不应该从不同的线程访问。


这似乎声明Qt中的每个函数和类应该被认为是非可重入和非线程安全的,除非明确声明这样。



但是,在 QRect QPoint ,例如,线程安全和重入都没有提到,但我发现很难相信它们不。事实上,这个旧讨论 a>说它在文档中的缺少:


这些类只是纯数据(几个原语),没有共享结构静态数据,因此它们是可重入的。因此,我们应该如何知道一个函数是可重入的还是一个可重入的函数。不?

解决方案

我认为这个问题唯一安全的答案是看源代码。显然,Qt文档是不够的。



通过Qt的reentrancy定义,有两个标准确定一个Qt类是否可重入:


  1. 它没有静态数据。

  2. 它只调用其他可重入类的可重入函数和方法。 >

访问单例类将违反2。


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?

解决方案

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.

这篇关于Qt文档和重入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆