OSDN Git Service

(split) LDP: Update drafts based on LDP 3.52 release
[linuxjm/LDP_man-pages.git] / draft / man3 / sem_wait.3
index c47d339..02099fc 100644 (file)
@@ -1,8 +1,7 @@
-'\" t
-.\" Hey Emacs! This file is -*- nroff -*- source.
-.\"
+.\" t
 .\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
 .\"
+.\" %%%LICENSE_START(VERBATIM)
 .\" 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.
 .\"
 .\" Formatted or processed versions of this manual, if unaccompanied by
 .\" the source, must acknowledge the copyright and authors of this work.
+.\" %%%LICENSE_END
+.\"
+.\"*******************************************************************
 .\"
-.\" Japanese Version Copyright (c) 2006 Akihiro MOTOKI all rights reserved.
-.\" Translated 2006-04-18, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
+.\" This file was generated with po4a. Translate the source file.
 .\"
-.TH SEM_WAIT 3 2010-02-25 "Linux" "Linux Programmer's Manual"
-.\"O .SH NAME
+.\"*******************************************************************
+.TH SEM_WAIT 3 2012\-05\-13 Linux "Linux Programmer's Manual"
 .SH 名前
-.\"O sem_wait, sem_timedwait, sem_trywait \- lock a semaphore
 sem_wait, sem_timedwait, sem_trywait \- セマフォをロックする
-.\"O .SH SYNOPSIS
 .SH 書式
 .nf
-.B #include <semaphore.h>
+\fB#include <semaphore.h>\fP
 .sp
-.BI "int sem_wait(sem_t *" sem );
+\fBint sem_wait(sem_t *\fP\fIsem\fP\fB);\fP
 .sp
-.BI "int sem_trywait(sem_t *" sem );
+\fBint sem_trywait(sem_t *\fP\fIsem\fP\fB);\fP
 .sp
-.BI "int sem_timedwait(sem_t *" sem ", const struct timespec *" abs_timeout );
+\fBint sem_timedwait(sem_t *\fP\fIsem\fP\fB, const struct timespec *\fP\fIabs_timeout\fP\fB);\fP
 .fi
 .sp
+\fI\-pthread\fP とリンクする。
 .sp
-.\"O Link with \fI\-lrt\fP or \fI\-pthread\fP.
-\fI\-lrt\fP または \fI\-pthread\fP でリンクする。
 .in -4n
-.\"O Feature Test Macro Requirements for glibc (see
-.\"O .BR feature_test_macros (7)):
-glibc 向けの機能検査マクロの要件
-.RB ( feature_test_macros (7)
-参照):
+glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
 .in
 .sp
-.BR sem_timedwait ():
-_POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600
-.\"O .SH DESCRIPTION
+\fBsem_timedwait\fP(): _POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600
 .SH 説明
-.\"O .BR sem_wait ()
-.\"O decrements (locks) the semaphore pointed to by
-.\"O .IR sem .
-.\"O If the semaphore's value is greater than zero,
-.\"O then the decrement proceeds, and the function returns, immediately.
-.\"O If the semaphore currently has the value zero,
-.\"O then the call blocks until either it becomes possible to perform
-.\"O the decrement (i.e., the semaphore value rises above zero),
-.\"O or a signal handler interrupts the call.
-.BR sem_wait ()
-は
-.I sem
-が指すセマフォの値を 1 減らす (ロックする)。
-セマフォの値が 0 より大きい場合、減算が実行され、関数は直ちに復帰する。
-セマフォの現在値が 0 の場合には、減算を実行できるようになる
-(つまり、セマフォの値が 0 より大きな値になる) まで、もしくは
-シグナルハンドラによって呼び出しが中断されるまで、
-関数呼び出しは停止 (block) する。
+\fBsem_wait\fP()  は \fIsem\fP が指すセマフォの値を 1 減らす (ロックする)。 セマフォの値が 0
+より大きい場合、減算が実行され、関数は直ちに復帰する。 セマフォの現在値が 0 の場合には、減算を実行できるようになる (つまり、セマフォの値が 0
+より大きな値になる) まで、もしくは シグナルハンドラによって呼び出しが中断されるまで、 関数呼び出しは停止 (block) する。
 
-.\"O .BR sem_trywait ()
-.\"O is the same as
-.\"O .BR sem_wait (),
-.\"O except that if the decrement cannot be immediately performed,
-.\"O then call returns an error
-.\"O .RI ( errno
-.\"O set to
-.\"O .BR EAGAIN )
-.\"O instead of blocking.
-.BR sem_trywait ()
-は
-.BR sem_wait ()
-と同じだが、セマフォ値の減算をすぐに実行できなかった場合に、
-停止 (block) するのではなくエラーで復帰する
-.RI ( errno
-に
-.B EAGAIN
-がセットされる) 点が異なる。
+\fBsem_trywait\fP()  は \fBsem_wait\fP()  と同じだが、セマフォ値の減算をすぐに実行できなかった場合に、 停止 (block)
+するのではなくエラーで復帰する (\fIerrno\fP に \fBEAGAIN\fP がセットされる) 点が異なる。
 
-.\"O .BR sem_timedwait ()
-.\"O is the same as
-.\"O .BR sem_wait (),
-.\"O except that
-.\"O .I abs_timeout
-.\"O specifies a limit on the amount of time that the call
-.\"O should block if the decrement cannot be immediately performed.
-.\"O The
-.\"O .I abs_timeout
-.\"O argument points to a structure that specifies an absolute timeout
-.\"O in seconds and nanoseconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC).
-.\"O This structure is defined as follows:
-.BR sem_timedwait ()
-は
-.BR sem_wait ()
-と同じだが、セマフォ値の減算をすぐに実行できなかった場合に
-関数呼び出しが停止する時間の上限を
-.I abs_timeout
-で指定する点が異なる。
-.I abs_timeout
-引き数は、タイムアウト時刻を指定する構造体へのポインタである。
-この構造体には、タイムアウト時刻を時刻紀元 (Epoch;
-1970-01-01 00:00:00 +0000 (UTC)) からの
-経過時間 (秒+ナノ秒) で指定する。
-構造体は以下のように定義されている:
+\fBsem_timedwait\fP()  は \fBsem_wait\fP()  と同じだが、セマフォ値の減算をすぐに実行できなかった場合に
+関数呼び出しが停止する時間の上限を \fIabs_timeout\fP で指定する点が異なる。 \fIabs_timeout\fP
+引き数は、タイムアウト時刻を指定する構造体へのポインタである。 この構造体には、タイムアウト時刻を時刻紀元 (Epoch; 1970\-01\-01
+00:00:00 +0000 (UTC)) からの 経過時間 (秒+ナノ秒) で指定する。 構造体は以下のように定義されている:
 
 .nf
 .in +4n
@@ -131,163 +71,60 @@ struct timespec {
 .in
 .fi
 .PP
-.\"O If the timeout has already expired by the time of the call,
-.\"O and the semaphore could not be locked immediately,
-.\"O then
-.\"O .BR sem_timedwait ()
-.\"O fails with a timeout error
-.\"O .RI ( errno
-.\"O set to
-.\"O .BR ETIMEDOUT ).
-関数呼び出し時点ですでにタイムアウトに指定した時刻が過ぎており、
-かつセマフォをすぐにロックできなかった場合は、
-.BR sem_timedwait ()
-はタイムアウトエラー
-.RI ( errno
-に
-.B ETIMEDOUT
-がセットされる) で失敗する。
+関数呼び出し時点ですでにタイムアウトに指定した時刻が過ぎており、 かつセマフォをすぐにロックできなかった場合は、 \fBsem_timedwait\fP()
+はタイムアウトエラー (\fIerrno\fP に \fBETIMEDOUT\fP がセットされる) で失敗する。
 
-.\"O If the operation can be performed immediately, then
-.\"O .BR sem_timedwait ()
-.\"O never fails with a timeout error, regardless of the value of
-.\"O .IR abs_timeout .
-.\"O Furthermore, the validity of
-.\"O .I abs_timeout
-.\"O is not checked in this case.
-セマフォ操作がすぐに実行できるときは、
-.I abs_timeout
-がどんな値であっても
-.BR sem_timedwait ()
-が失敗することは決してない。さらにいうと、この場合には
-.I abs_timeout
-の正当性の検査は行われない。
-.\"O .SH RETURN VALUE
+セマフォ操作がすぐに実行できるときは、 \fIabs_timeout\fP がどんな値であっても \fBsem_timedwait\fP()
+が失敗することは決してない。さらにいうと、この場合には \fIabs_timeout\fP の正当性の検査は行われない。
 .SH 返り値
-.\"O All of these functions return 0 on success;
-.\"O on error, the value of the semaphore is left unchanged,
-.\"O \-1 is returned, and
-.\"O .I errno
-.\"O is set to indicate the error.
-成功すると、これらの関数は 0 を返す。
-エラーの場合、セマフォの値を変更せずに、\-1 を返し、
-.I errno
-にエラーを示す値をセットする。
-.\"O .SH ERRORS
+成功すると、これらの関数は 0 を返す。 エラーの場合、セマフォの値を変更せずに、\-1 を返し、 \fIerrno\fP にエラーを示す値をセットする。
 .SH エラー
-.TP
-.B EINTR
-.\"O The call was interrupted by a signal handler; see
-.\"O .BR signal (7).
-呼び出しはシグナルハンドラにより中断された。
-.BR signal (7)
-参照。
-.TP
-.B EINVAL
-.\"O .I sem
-.\"O is not a valid semaphore.
-.I sem
-は有効なセマフォでない。
+.TP 
+\fBEINTR\fP
+呼び出しはシグナルハンドラにより中断された。 \fBsignal\fP(7)  参照。
+.TP 
+\fBEINVAL\fP
+\fIsem\fP は有効なセマフォではない。
 .PP
-.\"O The following additional error can occur for
-.\"O .BR sem_trywait ():
-.BR sem_trywait ()
-の場合には、上記に加えて以下のエラーも起こる。
-.TP
-.B EAGAIN
-.\"O The operation could not be performed without blocking (i.e., the
-.\"O semaphore currently has the value zero).
-停止 (block) せずにロック操作を完了できなかった (つまり、
-セマフォの現在の値が 0 であった)。
+\fBsem_trywait\fP()  の場合には、上記に加えて以下のエラーも起こる。
+.TP 
+\fBEAGAIN\fP
+停止 (block) せずにロック操作を完了できなかった (つまり、 セマフォの現在の値が 0 であった)。
 .PP
-.\"O The following additional errors can occur for
-.\"O .BR sem_timedwait ():
-.BR sem_timedwait ()
-の場合、以下のエラーも起こる。
-.TP
-.B EINVAL
-.\"O The value of
-.\"O .I abs_timeout.tv_nsecs
-.\"O is less than 0, or greater than or equal to 1000 million.
-.I abs_timeout.tv_nsecs
-の値が 0 未満、もしくは 1,000,000,000 以上である。
-.TP
-.B ETIMEDOUT
-.\"O The call timed out before the semaphore could be locked.
+\fBsem_timedwait\fP()  の場合、以下のエラーも起こる。
+.TP 
+\fBEINVAL\fP
+\fIabs_timeout.tv_nsecs\fP の値が 0 未満、もしくは 1,000,000,000 以上である。
+.TP 
+\fBETIMEDOUT\fP
+.\" POSIX.1-2001 also allows EDEADLK -- "A deadlock condition
+.\" was detected", but this does not occur on Linux(?).
 セマフォのロックに成功する前に時間切れとなった。
-.\"O .\" POSIX.1-2001 also allows EDEADLK -- "A deadlock condition
-.\"O .\" was detected", but this does not occur on Linux(?).
-.\" POSIX.1-2001 ではエラーとして EDEADLK も用意している。
-.\" これはデッドロック条件を検出したことを示すものだが、
-.\" Linux で発生することはない(?)
-.\"O .SH CONFORMING TO
-POSIX.1-2001.
-.\"O .SH NOTES
+.SH 準拠
+POSIX.1\-2001.
 .SH 注意
-.\"O A signal handler always interrupts a blocked call to
-.\"O one of these functions, regardless of the use of the
-.\"O .BR sigaction (2)
-.\"O .B SA_RESTART
-.\"O flag.
-シグナルハンドラは、
-.BR sigaction (2)
-の
-.B SA_RESTART
-フラグを使用しているかどうかに関わらず、これらの関数の呼び出しが
+.\" sem_wait() is always interrupted on most other implementations,
+.\" but on FreeBSD 5.4 SA_RESTART does cause restarting.
+シグナルハンドラは、 \fBsigaction\fP(2)  の \fBSA_RESTART\fP フラグを使用しているかどうかに関わらず、これらの関数の呼び出しが
 停止している場合、シグナルハンドラにより常に中断される。
-.\"O .\" sem_wait() is always interrupted on most other implementations,
-.\"O .\" but on FreeBSD 5.4 SA_RESTART does cause restarting.
-.\" sem_wait() は他のほとんどの実装では常に中断されるが、
-.\" FreeBSD 5.4 では SA_RESTART を指定しておくと実行が再開される。
-.\"O .SH EXAMPLE
 .SH 例
 .PP
-.\"O The (somewhat trivial) program shown below operates on an
-.\"O unnamed semaphore.
-.\"O The program expects two command-line arguments.
-.\"O The first argument specifies a seconds value that is used to
-.\"O set an alarm timer to generate a
-.\"O .B SIGALRM
-.\"O signal.
-.\"O This handler performs a
-.\"O .BR sem_post (3)
-.\"O to increment the semaphore that is being waited on in
-.\"O .I main()
-.\"O using
-.\"O .BR sem_timedwait ().
-.\"O The second command-line argument specifies the length
-.\"O of the timeout, in seconds, for
-.\"O .BR sem_timedwait ().
-.\"O The following shows what happens on two different runs of the program:
-以下に示す (ちょっとした) プログラムは名前なしセマフォの操作を行う。
-プログラムはコマンドライン引き数を 2 つ取る。
-最初の引き数には、
-.B SIGALRM
-シグナルを生成するためのアラームタイマーの設定に使われる値を
-秒単位で指定する。このシグナルハンドラは、
-.I main()
-内で
-.BR sem_timedwait ()
-を使って待っているセマフォを、
-.BR sem_post (3)
-を使って加算する。
-2番目の引き数には、
-.BR sem_timedwait ()
-に渡すタイムアウトまでの時間を秒単位で指定する。
+以下に示す (ちょっとした) プログラムは名前なしセマフォの操作を行う。 プログラムはコマンドライン引き数を 2 つ取る。 最初の引き数には、
+\fBSIGALRM\fP シグナルを生成するためのアラームタイマーの設定に使われる値を 秒単位で指定する。このシグナルハンドラは、 \fImain()\fP 内で
+\fBsem_timedwait\fP()  を使って待っているセマフォを、 \fBsem_post\fP(3)  を使って加算する。 2番目の引き数には、
+\fBsem_timedwait\fP()  に渡すタイムアウトまでの時間を秒単位で指定する。
 
 .in +4n
 .nf
-.RB "$" " ./a.out 2 3"
+$\fB ./a.out 2 3\fP
 About to call sem_timedwait()
 sem_post() from handler
-sem_getvalue() from handler; value = 1
 sem_timedwait() succeeded
-.RB "$" " ./a.out 2 1"
+$\fB ./a.out 2 1\fP
 About to call sem_timedwait()
 sem_timedwait() timed out
 .fi
 .in
-.\"O .SS Program source
 .SS プログラムのソース
 \&
 .nf
@@ -302,15 +139,15 @@ sem_timedwait() timed out
 
 sem_t sem;
 
-#define handle_error(msg) \\
+#define handle_error(msg) \e
     do { perror(msg); exit(EXIT_FAILURE); } while (0)
 
 static void
 handler(int sig)
 {
-    write(STDOUT_FILENO, "sem_post() from handler\\n", 24);
+    write(STDOUT_FILENO, "sem_post() from handler\en", 24);
     if (sem_post(&sem) == \-1) {
-        write(STDERR_FILENO, "sem_post() failed\\n", 18);
+        write(STDERR_FILENO, "sem_post() failed\en", 18);
         _exit(EXIT_FAILURE);
     }
 }
@@ -323,7 +160,7 @@ main(int argc, char *argv[])
     int s;
 
     if (argc != 3) {
-        fprintf(stderr, "Usage: %s <alarm\-secs> <wait\-secs>\\n",
+        fprintf(stderr, "Usage: %s <alarm\-secs> <wait\-secs>\en",
                 argv[0]);
         exit(EXIT_FAILURE);
     }
@@ -349,7 +186,7 @@ main(int argc, char *argv[])
 
     ts.tv_sec += atoi(argv[2]);
 
-    printf("main() about to call sem_timedwait()\\n");
+    printf("main() about to call sem_timedwait()\en");
     while ((s = sem_timedwait(&sem, &ts)) == \-1 && errno == EINTR)
         continue;       /* Restart if interrupted by handler */
 
@@ -357,19 +194,19 @@ main(int argc, char *argv[])
 
     if (s == \-1) {
         if (errno == ETIMEDOUT)
-            printf("sem_timedwait() timed out\\n");
+            printf("sem_timedwait() timed out\en");
         else
             perror("sem_timedwait");
     } else
-        printf("sem_timedwait() succeeded\\n");
+        printf("sem_timedwait() succeeded\en");
 
     exit((s == 0) ? EXIT_SUCCESS : EXIT_FAILURE);
 }
 .fi
-.\"O .SH "SEE ALSO"
 .SH 関連項目
-.BR clock_gettime (2),
-.BR sem_getvalue (3),
-.BR sem_post (3),
-.BR sem_overview (7),
-.BR time (7)
+\fBclock_gettime\fP(2), \fBsem_getvalue\fP(3), \fBsem_post\fP(3), \fBsem_overview\fP(7),
+\fBtime\fP(7)
+.SH この文書について
+この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.52 の一部
+である。プロジェクトの説明とバグ報告に関する情報は
+http://www.kernel.org/doc/man\-pages/ に書かれている。