线程支持
线程支持命令用于指定类或函数对多线程编程的支持级别。有三种支持级别:threadsafe
、reentrant
和nonreentrant
。
默认为nonreentrant
,这意味着相关类或函数不能被多个线程调用。Reentrant
和threadsafe
是主要用于类的级别。
Reentrant
这意味着被引用类中的所有函数都可以被多个线程同时调用,前提是每个函数的调用都引用了唯一的数据。而 则表示,即使每次调用都引用了共享数据,被引用类中的所有函数也可以被多个线程同时调用。threadsafe
当一个类被(\reentrant)或(\threadsafe)标记时,该类中的函数可以使用(\nonreentrant)命令标记为nonreentrant
。
示例
/*! \class QLocale \brief The QLocale class converts between numbers and their string representations in various languages. \reentrant \ingroup i18n \ingroup text QLocale is initialized with a language/country pair in its constructor and offers number-to-string and string-to-number conversion functions similar to those in QString. ... \nonreentrant Sets the global default locale to \a locale. These values are used when a QLocale object is constructed with no arguments. If this function is not called, the system's locale is used. \warning In a multithreaded application, the default locale should be set at application startup, before any non-GUI threads are created. \sa system(), c() */ void QLocale::setDefault(const QLocale &locale) { default_d = locale.d; }
当一个类被声明为可重入时,QDoc 会生成一个通知,并列出异常(已声明的非重入函数)。其中包含一个指向有关重入和线程安全的一般文档的链接。此外还有一个警告,即"警告:警告:此函数不是可重入函数。",并在非重入函数的文档中生成。
当一个类被声明为线程安全时,QDoc 也会生成同样的通知和警告。
更多信息,请参阅有关重入和线程安全的一般文档。
命令
\线程安全
线程安全(threadsafe)命令在文档中加入一行,表明相关类或函数是线程安全的,可以被多个线程同时调用,即使在单独调用引用共享数据时也是如此。
该命令必须独立成行。
该命令生成的文档与\reentrant命令生成的文档类似。参见上文介绍中的示例。
另请参见\reentrant和 \nonreentrant。
\reentrant
\reentrant 命令表示相关类或函数可以同时被多个线程调用,前提是每个调用都引用了自己的数据。请参阅上面的示例。
该命令必须独立成行。
另请参见\nonreentrant和 \threadsafe。
\不中断
nonreentrant命令表示相关类或函数不能被多个线程调用。Nonreentrant 是默认情况。
该命令必须独立成行。
当一个类被(\reentrant)或(\threadsafe)标记时,该类中的函数可以使用这条命令在要排除的函数的(\fn)注释中标记为nonreentrant
。
另请参阅\reentrant和 \threadsafe。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.