doc/ja_JP.eucJP/man/man3/pthread.3
Kazuo Horikawa c047a2ac17 Catch up with somewhat recent RELENG_4 section 3
Submitted by:FreeBSD jpman project members <man-jp@jp.FreeBSD.org>
2001-07-26 00:36:08 +00:00

453 lines
12 KiB
Groff

.\" Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by John Birrell.
.\" 4. Neither the name of the author nor the names of any co-contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" %FreeBSD: src/share/man/man3/pthread.3,v 1.12.2.2 2001/03/06 19:08:09 ru Exp %
.\"
.\" $FreeBSD$
.Dd September 10, 1998
.Dt PTHREAD 3
.Os BSD 4
.Sh 名称
.Nm pthread
.Nd POSIX スレッド関数
.Sh 書式
.Fd #include <pthread.h>
.Sh 解説
POSIX スレッドは、プロセス内でスレッド (thread) と呼ばれる
制御の複数のフローを要求するアプリケーションをサポートする関数群です。
マルチスレッドは、プログラムのパフォーマンスを改善するために使用されます。
.Pp
このセクションでは、
POSIX スレッド関数の概要について以下のグループに分けて説明します。
.Bl -bullet -offset indent
.It
スレッドルーチン
.It
属性オブジェクトルーチン
.It
mutex ルーチン
.It
条件変数ルーチン
.It
読取り/書込みロックルーチン
.It
スレッド固有コンテキストルーチン
.It
クリーンアップルーチン
.El
.Sh スレッドルーチン
.Bl -tag -width Er
.It Xo
.Ft int
.Fn pthread_create "pthread_t *thread" "const pthread_attr_t *attr" "void *(*start_routine)(void *)" "void *arg"
.Xc
新しい実行するスレッドを作成します。
.It Xo
.Ft int
.Fn pthread_detach "pthread_t thread"
.Xc
スレッドに削除のための印を付けます。
.It Xo
.Ft int
.Fn pthread_equal "pthread_t t1" "pthread_t t2"
.Xc
2 つのスレッドの ID を比較します。
.It Xo
.Ft void
.Fn pthread_exit "void *value_ptr"
.Xc
呼び出しているスレッドを終了します。
.It Xo
.Ft int
.Fn pthread_join "pthread_t thread" "void **value_ptr"
.Xc
呼び出しているスレッドが、指定したスレッドの終了を待つようにします。
.It Xo
.Ft int
.Fn pthread_cancel "pthread_t thread"
.Xc
スレッドの実行を取り消します。
.It Xo
.Ft int
.Fn pthread_once "pthread_once_t *once_control" "void (*init_routine)(void)"
.Xc
初期化ルーチンを一度だけ呼び出します。
.It Xo
.Ft pthread_t
.Fn pthread_self void
.Xc
呼び出しているスレッドの ID を返します。
.El
.Sh 属性オブジェクトルーチン
.Bl -tag -width Er
.It Xo
.Ft int
.Fn pthread_attr_destroy "pthread_attr_t *attr"
.Xc
スレッドの属性オブジェクトを破壊します。
.It Xo
.Ft int
.Fn pthread_attr_getinheritsched "const pthread_attr_t *attr" "int *inheritsched"
.Xc
スレッドの属性オブジェクトから継承スケジューリング属性を取得します。
.It Xo
.Ft int
.Fn pthread_attr_getschedparam "const pthread_attr_t *attr" "struct sched_param *param"
.Xc
スレッドの属性オブジェクトからスケジューリングパラメータ属性を取得します。
.It Xo
.Ft int
.Fn pthread_attr_getschedpolicy "const pthread_attr_t *attr" "int *policy"
.Xc
スレッドの属性オブジェクトからスケジューリング方針属性を取得します。
.It Xo
.Ft int
.Fn pthread_attr_getscope "const pthread_attr_t *attr" "int *contentionscope"
.Xc
スレッドの属性オブジェクトからコンテンション範囲属性を取得します。
.It Xo
.Ft int
.Fn pthread_attr_getstacksize "const pthread_attr_t *attr" "size_t *stacksize"
.Xc
スレッドの属性オブジェクトからスタックサイズ属性を取得します。
.It Xo
.Ft int
.Fn pthread_attr_getstackaddr "const pthread_attr_t *attr" "void **stackaddr"
.Xc
スレッドの属性オブジェクトからスタックアドレス属性を取得します。
.It Xo
.Ft int
.Fn pthread_attr_getdetachstate "const pthread_attr_t *attr" "int *detachstate"
.Xc
スレッドの属性オブジェクトからデタッチ状態属性を取得します。
.It Xo
.Ft int
.Fn pthread_attr_init "pthread_attr_t *attr"
.Xc
スレッド属性オブジェクトをデフォルト値で初期化します。
.It Xo
.Ft int
.Fn pthread_attr_setinheritsched "pthread_attr_t *attr" "int inheritsched"
.Xc
スレッドの属性オブジェクトに継承スケジューリング属性を設定します。
.It Xo
.Ft int
.Fn pthread_attr_setschedparam "pthread_attr_t *attr" "const struct sched_param *param"
.Xc
スレッドの属性オブジェクトにスケジューリングパラメータ属性を設定します。
.It Xo
.Ft int
.Fn pthread_attr_setschedpolicy "pthread_attr_t *attr" "int policy"
.Xc
スレッドの属性オブジェクトにスケジューリング方針属性を設定します。
.It Xo
.Ft int
.Fn pthread_attr_setscope "pthread_attr_t *attr" "int contentionscope"
.Xc
スレッドの属性オブジェクトにコンテンション範囲属性を設定します。
.It Xo
.Ft int
.Fn pthread_attr_setstacksize "pthread_attr_t *attr" "size_t stacksize"
.Xc
スレッドの属性オブジェクトにスタックサイズ属性を設定します。
.It Xo
.Ft int
.Fn pthread_attr_setstackaddr "pthread_attr_t *attr" "void *stackaddr"
.Xc
スレッドの属性オブジェクトにスタックアドレス属性を設定します。
.It Xo
.Ft int
.Fn pthread_attr_setdetachstate "pthread_attr_t *attr" "int detachstate"
.Xc
スレッドの属性オブジェクトにデタッチ状態属性を設定します。
.El
.Sh mutex ルーチン
.Bl -tag -width Er
.It Xo
.Ft int
.Fn pthread_mutexattr_destroy "pthread_mutexattr_t *attr"
.Xc
mutex の属性オブジェクトを破壊します。
.It Xo
.Ft int
.Fn pthread_mutexattr_init "pthread_mutexattr_t *attr"
.Xc
mutex の属性オブジェクトをデフォルト値で初期化します。
.It Xo
.Ft int
.Fn pthread_mutex_destroy "pthread_mutex_t *mutex"
.Xc
mutex を破壊します。
.It Xo
.Ft int
.Fn pthread_mutex_init "pthread_mutex_t *mutex" "const pthread_mutexattr_t *attr"
.Xc
mutex を指定された属性で初期化します。
.It Xo
.Ft int
.Fn pthread_mutex_lock "pthread_mutex_t *mutex"
.Xc
mutex をロックして、mutex が利用可能になるまでブロックします。
.It Xo
.Ft int
.Fn pthread_mutex_trylock "pthread_mutex_t *mutex"
.Xc
mutex をロックしようとしますが、mutex が現在のスレッドを含めた
別のスレッドによってロックされている場合には、ブロックしません。
.It Xo
.Ft int
.Fn pthread_mutex_unlock "pthread_mutex_t *mutex"
.Xc
mutex のロックを解除します。
.El
.Sh 条件変数ルーチン
.Bl -tag -width Er
.It Xo
.Ft int
.Fn pthread_condattr_init "pthread_condattr_t *attr"
.Xc
条件変数の属性オブジェクトをデフォルト値で初期化します。
.It Xo
.Ft int
.Fn pthread_condattr_destroy "pthread_condattr_t *attr"
.Xc
条件変数の属性オブジェクトを破壊します。
.It Xo
.Ft int
.Fn pthread_cond_broadcast "pthread_cond_t *cond"
.Xc
指定された条件変数で現在ブロックされている
全てのスレッドのブロックを解除します。
.It Xo
.Ft int
.Fn pthread_cond_destroy "pthread_cond_t *cond"
.Xc
条件変数を破壊します。
.It Xo
.Ft int
.Fn pthread_cond_init "pthread_cond_t *cond" "const pthread_condattr_t *attr"
.Xc
条件変数を指定された属性で初期化します。
.It Xo
.Ft int
.Fn pthread_cond_signal "pthread_cond_t *cond"
.Xc
指定された条件変数で現在ブロックされている
少なくとも 1 つのスレッドのブロックを解除します。
.It Xo
.Ft int
.Fn pthread_cond_timedwait "pthread_cond_t *cond" "pthread_mutex_t *mutex" "const struct timespec *abstime"
.Xc
条件を指定された時間内で待機し、指定された mutex をロックします。
.It Xo
.Ft int
.Fn pthread_cond_wait "pthread_cond_t *" "pthread_mutex_t *mutex"
.Xc
条件を待機し、指定された mutex をロックします。
.El
.Sh 読取り/書込みロックルーチン
.Bl -tag -width Er
.It Xo
.Ft int
.Fn pthread_rwlock_destroy "pthread_rwlock_t *lock"
.Xc
読取り/書込みロックオブジェクトを破壊します。
.It Xo
.Ft int
.Fn pthread_rwlock_init "pthread_rwlock_t *lock" "const pthread_rwlockattr_t *attr"
.Xc
読取り/書込みロックオブジェクトを初期化します。
.It Xo
.Ft int
.Fn pthread_rwlock_rdlock "pthread_rwlock_t *lock"
.Xc
読取り/書込みロックを読取り用にロックし、
ロックを取得できるようになるまでブロックします。
.It Xo
.Ft int
.Fn pthread_rwlock_tryrdlock "pthread_rwlock_t *lock"
.Xc
読取り/書込みロックを読取り用にロックしようとしますが、
ロックできない場合にはブロックしません。
.It Xo
.Ft int
.Fn pthread_rwlock_trywrlock "pthread_rwlock_t *lock"
.Xc
読取り/書込みロックを書込み用にロックしようとしますが、
ロックできない場合にはブロックしません。
.It Xo
.Ft int
.Fn pthread_rwlock_unlock "pthread_rwlock_t *lock"
.Xc
読取り/書込みロックのロックを解除します。
.It Xo
.Ft int
.Fn pthread_rwlock_wrlock "pthread_rwlock_t *lock"
.Xc
読取り/書込みロックを書込み用にロックし、
ロックを取得できるようになるまでブロックします。
.It Xo
.Ft int
.Fn pthread_rwlockattr_destroy "pthread_rwlockattr_t *attr"
.Xc
読取り/書込みロックの属性オブジェクトを破壊します。
.It Xo
.Ft int
.Fn pthread_rwlockattr_getpshared "const pthread_rwlockattr_t *attr" "int *pshared"
.Xc
読取り/書込みロックの属性オブジェクトのプロセス共有設定を取得します。
.It Xo
.Ft int
.Fn pthread_rwlockattr_init "pthread_rwlockattr_t *attr"
.Xc
読取り/書込みロックの属性オブジェクトを初期化します。
.It Xo
.Ft int
.Fn pthread_rwlockattr_setpshared "pthread_rwlockattr_t *attr" "int pshared"
.Xc
読取り/書込みロックの属性オブジェクトのプロセス共有設定を設定します。
.El
.Sh スレッド固有コンテキストルーチン
.Bl -tag -width Er
.It Xo
.Ft int
.Fn pthread_key_create "pthread_key_t *key" "void (*routine)(void *)"
.Xc
スレッド固有のデータキーを作成します。
.It Xo
.Ft int
.Fn pthread_key_delete "pthread_key_t key"
.Xc
スレッド固有のデータキーを削除します。
.It Xo
.Ft "void *"
.Fn pthread_getspecific "pthread_key_t key"
.Xc
指定されたキーのスレッド固有の値を取得します。
.It Xo
.Ft int
.Fn pthread_setspecific "pthread_key_t key" "const void *value_ptr"
.Xc
指定されたキーのスレッド固有の値を設定します。
.El
.Sh クリーンアップルーチン
.Bl -tag -width Er
.It Xo
.Ft void
.Fn pthread_cleanup_pop "int execute"
.Xc
呼び出しているスレッドの取り消しクリーンアップスタックの最初のルーチンを
削除し、オプションでそのルーチンを実行します。
.It Xo
.Ft void
.Fn pthread_cleanup_push "void (*routine)(void *)" "void *routine_arg"
.Xc
呼び出しているスレッドの取り消しスタックに指定された取り消しクリーンアップ
ハンドラを積みます。
.El
.Sh インストレーション
現在の
.Fx
POSIX スレッドの実装は、スレッドセーフな libc 関数とスレッド関数を含む
ライブラリ
.Fa libc_r
で構築されています。このライブラリはスレッドアプリケーションの
.Fa libc
を置き換えます。
.Pp
デフォルトでは、
.Fa libc_r
は 'make world' の一部として構築されます。この構築を無効にするには、
.Xr make 1
に '-DNOLIBC_R' オプションを与えなければなりません。
.Pp
スレッド化されたプロセスを簡単にリンクするために、gcc に
.Fx
固有のオプションが追加されています。
.Fa gcc -pthread
はスレッド化されたプロセスに
.Fa libc
に代って
.Fa libc_r
をリンクします。
.Sh 関連項目
.Xr pthread_create 3 ,
.Xr pthread_detach 3 ,
.Xr pthread_equal 3 ,
.Xr pthread_exit 3 ,
.Xr pthread_join 3 ,
.Xr pthread_once 3 ,
.Xr pthread_self 3 ,
.Xr pthread_mutex_destroy 3 ,
.Xr pthread_mutex_init 3 ,
.Xr pthread_mutex_lock 3 ,
.Xr pthread_mutex_trylock 3 ,
.Xr pthread_mutex_unlock 3 ,
.Xr pthread_cond_broadcast 3 ,
.Xr pthread_cond_destroy 3 ,
.Xr pthread_cond_init 3 ,
.Xr pthread_cond_signal 3 ,
.Xr pthread_cond_timedwait 3 ,
.Xr pthread_cond_wait 3 ,
.Xr pthread_rwlock_destroy 3 ,
.Xr pthread_rwlock_init 3 ,
.Xr pthread_rwlock_rdlock 3 ,
.Xr pthread_rwlock_unlock 3 ,
.Xr pthread_rwlock_wrlock 3 ,
.Xr pthread_rwlockattr_destroy 3 ,
.Xr pthread_rwlockattr_getpshared 3 ,
.Xr pthread_rwlockattr_init 3 ,
.Xr pthread_rwlockattr_setpshared 3 ,
.Xr pthread_key_delete 3 ,
.Xr pthread_getspecific 3 ,
.Xr pthread_setspecific 3 ,
.Xr pthread_cleanup_pop 3 ,
.Xr pthread_cleanup_push 3
.Sh 規格
.Fa pthread_
接頭語が付き、
.Fa _np
接尾語または
.Fa pthread_rwlock
接頭語が付いていない
.Fa libc_r
の関数は、
.St -p1003.1-96
に適合しています。
.Pp
.Fa pthread_
接頭語および
.Fa _np
接尾語が付いた libc_r の関数は、POSIX スレッドへの非ポータブル拡張です。
.Pp
.Fa pthread_rwlock
接頭語が付いた libc_r の関数は、
.St -susv2
の The Open Group によって作成された拡張です。