线程支持

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 命令。

范例

\beginqdoc
    \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()
\endqdoc
void QLocale::setDefault(const QLocale &locale)
{
    default_d = locale.d;
}

					

QDoc renders this as:

QLocale Class Reference

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() .

...


成员类型文档编制

...

void QLocale::setDefault ( const QLocale & locale )

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.

另请参阅 system() and c() .

...

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 .

命令

\threadsafe

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 .

\reentrant

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 .

\nonreentrant

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