简体   繁体   English

类实例线程关联是否会对其数据产生任何影响?

[英]Does a class instance thread affinity have any impact on its data?

We know from the QThread documentation 我们从QThread 文档中了解到

A QObject instance is said to have a thread affinity, or that it lives in a certain thread. 据说QObject实例具有线程亲和性,或者它存在于某个线程中。 When a QObject receives a queued signal or a posted event, the slot or event handler will run in the thread that the object lives in. 当QObject收到排队信号或发布事件时,插槽或事件处理程序将在对象所在的线程中运行。

Does the thread affinity have any impact on the class instance data? 线程关联是否会对类实例数据产生任何影响? Does the class data become thread data? 类数据是否成为线程数据?

Apart from the above, the reason I am asking is because I want to pass a pointer/reference of another class in its constructor. 除了上述之外,我问的原因是因为我想在其构造函数中传递另一个类的指针/引用。 If I am being object oriented, I shall not access its data directly but if I call a member function of the other class, will it also be called in this class's thread? 如果我是面向对象的,我不会直接访问它的数据,但如果我调用另一个类的成员函数,它是否也会在这个类的线程中调用?

Does the thread affinity has any impact on the class data? 线程关联是否会对类数据产生任何影响?

No, a QObject's thread affinity only controls which thread its slot and event handlers run in. 不,QObject的线程关联仅控制其插槽和事件处理程序在哪个线程中运行。

Does the class data becomes a thread data? 类数据是否成为线程数据?

Class data means class static data members - that can't possibly be affected by the thread affinity of each instance. 类数据表示类静态数据成员 - 不可能受每个实例的线程关联性的影响。 Instance data isn't somehow made thread-local either: thread-local storage can be very limited, and there's simply no reason to force every instance into it. 实例数据也不会以某种方式成为线程本地:线程本地存储可能非常有限,并且没有理由强制每个实例进入它。

Apart from the above ... 除了以上......

If you don't issue a signal or event, normal method calls are just method calls. 如果您不发出信号或事件,则正常方法调用只是方法调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM