OSDN Git Service

471c9427a6009b2a0723fde57b491bdb29a5b593
[linuxjm/LDP_man-pages.git] / draft / man3 / sem_init.3
1 '\" t
2 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\"
4 .\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
5 .\"
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
9 .\"
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
14 .\"
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein.  The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\"
26 .\" Japanese Version Copyright (c) 2006 Akihiro MOTOKI all rights reserved.
27 .\" Translated 2006-04-18, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
28 .\"
29 .TH SEM_INIT 3 2008-07-27 "Linux" "Linux Programmer's Manual"
30 .\"O .SH NAME
31 .SH 名前
32 .\"O sem_init \- initialize an unnamed semaphore
33 sem_init \- 名前なしセマフォを初期化する
34 .\"O .SH SYNOPSIS
35 .SH 書式
36 .nf
37 .B #include <semaphore.h>
38 .sp
39 .BI "int sem_init(sem_t *" sem ", int " pshared ", unsigned int " value );
40 .fi
41 .sp
42 .\"O Link with \fI\-lrt\fP or \fI\-pthread\fP.
43 \fI\-lrt\fP または \fI\-pthread\fP でリンクする。
44 .\"O .SH DESCRIPTION
45 .SH 説明
46 .\"O .BR sem_init ()
47 .\"O initializes the unnamed semaphore at the address pointed to by
48 .\"O .IR sem .
49 .\"O The
50 .\"O .I value
51 .\"O argument specifies the initial value for the semaphore.
52 .BR sem_init ()
53 は、
54 .I sem
55 が指すアドレスにある名前なしセマフォを初期化する。
56 .I value
57 引き数はそのセマフォの初期値を指定する。
58
59 .\"O The
60 .\"O .I pshared
61 .\"O argument indicates whether this semaphore is to be shared
62 .\"O between the threads of a process, or between processes.
63 .I pshared
64 引き数は、このセマフォがプロセス内のスレッド間で共有されるのか、
65 プロセス間で共有されるのか、を示す。
66
67 .\"O If
68 .\"O .I pshared
69 .\"O has the value 0,
70 .\"O then the semaphore is shared between the threads of a process,
71 .\"O and should be located at some address that is visible to all threads
72 .\"O (e.g., a global variable, or a variable allocated dynamically on
73 .\"O the heap).
74 .I pshared
75 が 0 の場合、セマフォはプロセス内のスレッド間で共有される。
76 セマフォはすべてのスレッドから参照可能なアドレスに配置すべきである
77 (例えば、大域変数や、ヒープ上に動的に割り当てられた変数など)。
78
79 .\"O If
80 .\"O .I pshared
81 .\"O is nonzero, then the semaphore is shared between processes,
82 .\"O and should be located in a region of shared memory (see
83 .\"O .BR shm_open (3),
84 .\"O .BR mmap (2),
85 .\"O and
86 .\"O .BR shmget (2)).
87 .\"O (Since a child created by
88 .\"O .BR fork (2)
89 .\"O inherits its parent's memory mappings, it can also access the semaphore.)
90 .\"O Any process that can access the shared memory region
91 .\"O can operate on the semaphore using
92 .\"O .BR sem_post (3),
93 .\"O .BR sem_wait (3),
94 .\"O etc.
95 .I pshared
96 が 0 以外の場合、セマフォはプロセス間で共有される。セマフォは
97 共有メモリ領域に配置すべきである
98 .RB ( shm_open (3),
99 .BR mmap (2),
100 .BR shmget (2)
101 参照)。
102 .RB ( fork (2)
103 で生成された子プロセスは親プロセスのメモリマッピングを継承するため、
104 子プロセスもセマフォにアクセスできる。)
105 共有メモリ領域にアクセスできるプロセスならば、どのプロセスでも
106 .BR sem_post (3)
107
108 .BR sem_wait (3)
109 などを使ってセマフォを操作できる。
110
111 .\"O Initializing a semaphore that has already been initialized
112 .\"O results in undefined behavior.
113 すでに初期化済のセマフォを初期化した場合の挙動は定義されていない。
114 .\"O .SH RETURN VALUE
115 .SH 返り値
116 .\"O .BR sem_init ()
117 .\"O returns 0 on success;
118 .\"O on error, \-1 is returned, and
119 .\"O .I errno
120 .\"O is set to indicate the error.
121 成功すると、
122 .BR sem_init ()
123 は 0 を返す。エラーの場合、\-1 を返し、
124 .I errno
125 にエラーを示す値をセットする。
126 .\"O .SH ERRORS
127 .SH エラー
128 .TP
129 .B EINVAL
130 .\"O .I value
131 .\"O exceeds
132 .\"O .BR SEM_VALUE_MAX .
133 .I value
134
135 .B SEM_VALUE_MAX
136 を超えている。
137 .TP
138 .B ENOSYS
139 .\"O .I pshared
140 .\"O is nonzero,
141 .\"O but the system does not support process-shared semaphores (see
142 .\"O .BR sem_overview (7)).
143 .I pshared
144 が 0 以外だが、システムがプロセス共有セマフォをサポートしていない
145 .RB ( sem_overview (7)
146 参照)。
147 .\"O .SH CONFORMING TO
148 .SH 準拠
149 POSIX.1-2001.
150 .\"O .SH NOTES
151 .SH 注意
152 .\"O Bizarrely, POSIX.1-2001 does not specify the value that should
153 .\"O be returned by a successful call to
154 .\"O .BR sem_init ().
155 .\"O POSIX.1-2008 rectifies this, specifying the zero return on success.
156 妙なことに、POSIX.1-2001 は
157 .BR sem_init ()
158 が成功した場合に返すべき値を規定していない。
159 POSIX.1-2008 ではこれが修正され、成功時には 0 を返すことが規定された。
160 .\"O .SH "SEE ALSO"
161 .SH 関連項目
162 .BR sem_destroy (3),
163 .BR sem_post (3),
164 .BR sem_wait (3),
165 .BR sem_overview (7)