マルチスレッドのプログラミング

スレッドの初期化ルーチンの呼び出し

スレッド化されたプロセス内の pthread_once(3C) は、最初に呼び出されたとき、初期化ルーチンを呼び出します。 プロセス内の任意のスレッドからの 2 回目以降の pthread_once() の呼び出しは何の効果もありません。

pthread_once の構文

int  pthread_once(pthread_once_t *once_control, void (*init_routine)(void));
#include <pthread.h>

pthread_once_t once_control = PTHREAD_ONCE_INIT;
int ret;

ret = pthread_once(&once_control, 
init_routine);

once_control パラメータは、該当する初期化ルーチンがすでに呼び出されているかどうかを判定します。

pthread_once の戻り値

pthread_once() は、正常終了時に 0 を返します。それ以外の戻り値は、エラーが発生したことを示します。以下の条件が検出されると pthread_once() は失敗し、対応する値を返します。


EINVAL

説明:

once_control または init_routineNULL です。