このセクションの内容
マルチスレッド アプリケーションをテストするには、ビルド設定のコンパイラ オプションに次のオプションを追加します。ビルド設定の詳細については 「プロジェクトとファイルのオプション設定」 を参照してください。
"-DCPPTEST_THREADS=1"
このオプションは、C/C++test ランタイム ライブラリのマルチスレッド サポートを有効にし、スレッド関係のルーチンに対するセーフ スタブの使用を無効にします。
既知の問題と制限事項は以下のとおりです。
C/C++test のデフォルトのランタイム ライブラリは、あらかじめマルチ スレッドをサポートしています。たとえば組込みのテストを行うなどのために、マルチスレッドをサポートするカスタム ランタイム ライブラリをビルドする場合を除いて、追加の作業を行う必要はありません。マルチスレッドをサポートするカスタム ランタイム ライブラリをビルドする必要がある場合、コンパイラ コマンドラインに次を追加します。 "- DCPPTEST_THREADS_ENABLED=1"
ランタイム ライブラリ実装は、以下の種類のスレッド API を使用できます。
他のスレッド API (またはカスタム API) を使用する必要がある場合、以下の型とルーチンを実装する必要があります。
C/C++test ランタイム ソースの CppTestThread.c ファイルには、スレッド サポート ルーチンの定義が含まれていることに注意してください。このファイルをサンプルとして使用したり、変更のベースとすることができます。
typedef IMPLEMENTATION_DEPENDENT_TYPE CppTestThreadKey; /** * Creates key for thread local storage data * Returns 0 on success */ extern int localThreadKeyCreate(CppTestThreadKey* key); /** * Deletes key for thread local storage data * Returns 0 on success */ extern int localThreadKeyDelete(CppTestThreadKey key); /** * Returns a thread specific value associate with a key */ extern void* localThreadGetSpecific(CppTestThreadKey key); /** * Associate a thread specific value with a key * Returns 0 on success */ extern int localThreadSetSpecific(CppTestThreadKey key, void* value); |
注意: C/C++test ランタイムは、mutex を静的に初期化できると仮定します。
typedef IMPLEMENTATION_DEPENDENT_TYPE CppTestThreadMutex; #define CPPTEST_THREADS_MUTEX_STATIC_INIT <IMPLEMENTATION_DEPENDENT_STATIC_INITIALIZER> /** * Initializes mutex * @return 0 on success */ extern int localThreadMutexInit(CppTestThreadMutex* mutex); /** * Destroy and release resources used by mutex * @return 0 on success */ extern int localThreadMutexDestroy(CppTestThreadMutex* mutex); /** * Lock mutext and return when calling thread becames is owner of it. * @return 0 on success */ extern int localThreadMutexLock(CppTestThreadMutex* mutex); /** * Releases mutex owned by calling thread. * @return 0 on success */ extern int localThreadMutexUnlock(CppTestThreadMutex* mutex); |
/** * Exits calling thread * (never returns) */ extern void localThreadExit(); /** * @return non-zero if threads already finished execution */ extern int localThreadFinished(CppTestThread* thread); /** * @return non-zero if threads are supported in current build * (proper macros, libraries, compiler options were used). */ extern int localThreadsSupported(void); /** * Initializes given thread structure */ extern void localThreadInit(CppTestThread* thread); |