.\" Copyright (C) 1996-1999 Free Software Foundation, Inc. .\" .\" Permission is granted to make and distribute verbatim copies of .\" this manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of .\" this manual under the conditions for verbatim copying, provided that .\" the entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Permission is granted to copy and distribute translations of this .\" manual into another language, under the above conditions for modified .\" versions, except that this permission notice may be stated in a .\" translation approved by the Foundation. .\" .\" Copyright (C) 1996 Xavier Leroy. .\" .\" Japanese Version Copyright (C) 2002-2003 Suzuki Takashi .\" all rights reserved. .\" Translated Wed Jan 1 18:29:55 JST 2003 .\" by Suzuki Takashi. .\" .\" .TH PTHREAD_ONCE 3 LinuxThreads .SH 名前 pthread_once \- 1 回きりの初期化 .SH 書式 .B #include .BI "pthread_once_t " once_control " = PTHREAD_ONCE_INIT;" .BI "int pthread_once(pthread_once_t *" once_control ", void (*" init_routine ") (void));" .SH 説明 .B "pthread_once" の目的は、 初期化コードが高々 1 回しか実行されないようにすることである。 引数 .I "once_control" は静的変数または外部変数を指し示し、静的に .B "PTHREAD_ONCE_INIT" という値に初期化されていなければならない。 最初に引数 .I "once_control" とともに .B "pthread_once" が呼び出されたときには、 .I "init_routine" を引数なしで呼び出し、 変数 .I "once_control" の値を変更して初期化が行なわれたことを記録する。 その後同じ引数 .B "once_control" とともに .B "pthread_once" が呼び出されたときは何もしない。 .SH 返り値 .B "pthread_once" は常に 0 を返す。 .SH エラー なし。 .SH 著者 Xavier Leroy [訳注] glibc-linuxthreads の最新のドキュメントは Texinfo 形式で提供されている。 以下は glibc-linuxthreads-2.3.1 の Texinfo ファイルからの引用で、 「説明」への追記にあたるものである。 スレッドが .I "init_routine" を実行中に取り消しされた場合、 .I "once_control" はリセットされ、将来 .B "pthread_once" が呼び出されたとき初期化ルーチンは再び実行される。 1 つまたは複数のスレッドが .B "pthread_once" の初期化ルーチンを実行中に プロセスが fork したときには、 子プロセスではそれぞれの .I "once_control" 変数はリセットされたように見え、 子プロセスで .B "pthread_once" が呼び出されたとき初期化ルーチンは実行される。