The thread support commands are for specifying the level of support for multithreaded programming in a class or function. There are three levels of support:
threadsafe
,
可重入
and
nonreentrant
.
默认为
nonreentrant
which means that the associated class or function cannot be called by multiple threads.
Reentrant
and
threadsafe
are levels primarily used for classes.
Reentrant
means that all the functions in the referenced class can be called simultaneously by multiple threads, provided that each invocation of the functions reference unique data. While
threadsafe
means that all the functions in the referenced class can be called simultaneously by multiple threads even when each invocation references shared data.
When a class is marked
\reentrant
or
\threadsafe
, functions in that class can be marked
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 被使用。 \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 renders this as:
The QLocale class converts between numbers and their string representations in various languages. More...
#include <QLocale>
注意: All the functions in this class are 可重入 , except setDefault ().
...
...
Sets the global default locale to 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.
警告: In a multithreaded application, the default locale should be set at application startup, before any non-GUI threads are created.
警告: This function is not reentrant.
...
As shown above, QDoc generates a notification when a class is declared reentrant, and lists the exceptions (the declared nonreentrant functions). A link to the general documentation on reentrancy and thread-safety is included. In addition a warning, " 警告 : This function is not reentrant.", is generated in the nonreentrant functions' documentation.
QDoc will generate the same notification and warnings when a class is declared threadsafe.
For more information see the general documentation on reentrancy and thread-safety .
The \threadsafe command includes a line in the documentation to indicate that the associated class or function is threadsafe and can be called simultaneously by multiple threads, even when separate invocations reference shared data.
The command must stand on its own line.
The documentation generated from this command will be similar to the what is generated for the \reentrant command. See the example above in the introduction .
另请参阅 \reentrant and \nonreentrant .
The \reentrant command indicates that the associated class or function can be called simultaneously by multiple threads, provided that each invocation references its own data. See the 范例 above.
The command must stand on its own line.
另请参阅 \nonreentrant and \threadsafe .
The \nonreentrant command indicates that the associated class or function cannot be called by multiple threads. Nonreentrant is the default case.
The command must stand on its own line.
When a class is marked
\reentrant
or
\threadsafe
, functions in that class can be marked
nonreentrant
using this command in the
\fn
comment of the functions to be excluded.
另请参阅 \reentrant and \threadsafe .
状态 Relating Things