このページでは

スレッドのサポート

スレッドサポートコマンドは、クラスや関数におけるマルチスレッドプログラミングのサポートレベルを指定するためのものです。サポートレベルには、threadsafe 、reentrant 、nonreentrant の3つがあります。

デフォルトはnonreentrant であり、これは関連するクラスや関数が複数のスレッドから呼び出せないことを意味します。Reentrant およびthreadsafe は、主にクラスで使用されるレベルです。

Reentrant は、参照されるクラス内のすべての関数が、各呼び出しが一意のデータを参照する場合に限り、複数のスレッドから同時に呼び出せることを意味します。一方、threadsafe は、各呼び出しが共有データを参照する場合であっても、参照されるクラス内のすべての関数が複数のスレッドから同時に呼び出せることを意味します。

クラスが \reentrant または \threadsafenonreentrant でマークされている場合、そのクラス内の関数は \nonreentrant コマンドを使用して、そのクラスの関数にxml-ph-0000@deepl.internalを指定できます。

例

/*!
    \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

\threadsafe コマンドには、関連するクラスや関数がスレッドセーフであり、個別の呼び出しで共有データを参照する場合でも、複数のスレッドから同時に呼び出すことができることを示す記述がドキュメントに含まれています。

このコマンドは、単独の行に記述する必要があります。

このコマンドによって生成されるドキュメントは、 \reentrant コマンドに対して生成されるものと類似したものになります。冒頭の例を参照してください。

関連項目 \reentrant および \nonreentrantも参照してください。

\reentrant

\reentrant コマンドは、各呼び出しが独自のデータを参照することを条件として、関連するクラスまたは関数が複数のスレッドから同時に呼び出せることを示しています。上記の例を参照してください。

このコマンドは、単独の行に記述する必要があります。

関連項目 \nonreentrant および \threadsafeを参照してください。

\nonreentrant

\nonreentrant コマンドは、関連するクラスまたは関数が複数のスレッドから呼び出せないことを示します。デフォルトは非再入型です。

このコマンドは、単独の行に記述する必要があります。

クラスが \reentrant または \threadsafeとマークされている場合、そのクラス内の関数は、nonreentrant として、このコマンドを \fn 除外する関数のコメント内で、このコマンドを使用してxml-ph-0000@deepl.internalとマークすることができます。

関連項目 \reentrant および \threadsafeも参照してください。

© 2026 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.