OSDN Git Service

def54013bac32e2a6bb3b289c1c4c4631ce675e1
[linuxjm/LDP_man-pages.git] / draft / man7 / futex.7
1 .\" This page is made available under the MIT license.
2 .\"
3 .\" This manpage has been automatically generated by docbook2man
4 .\" from a DocBook document.  This tool can be found at:
5 .\" <http://shell.ipoline.com/~elmert/comp/docbook2X/>
6 .\" Please send any bug reports, improvements, comments, patches,
7 .\" etc. to Steve Cheng <steve@ggi-project.org>.
8 .\"
9 .\" Japanese Version Copyright(C) 2003 Suzuki Takashi
10 .\"         all rights reserved.
11 .\" Translated Fri Oct 24 10:37:10 JST 2003
12 .\"         by Suzuki Takashi.
13 .\"
14 .\"WORD: contend                競合する
15 .\"WORD: sleep                  起床待ちする
16 .\"WORD: wake                   起床する
17 .\"WORD: wake up                起床する
18 .\"
19 .TH FUTEX 7 2002-12-31 "Linux" "Linux Programmer's Manual"
20 .\"O .SH NAME
21 .SH 名前
22 .\"O futex \- Fast Userspace Locking
23 futex - 高速ユーザ空間ロック機構
24 .\"O .SH SYNOPSIS
25 .SH 書式
26 .nf
27 .B #include <linux/futex.h>
28 .fi
29 .\"O .SH DESCRIPTION
30 .SH 説明
31 .PP
32 .\"O The Linux kernel provides futexes ("Fast Userspace muTexes")
33 .\"O as a building block for fast userspace
34 .\"O locking and semaphores.
35 .\"O Futexes are very basic and lend themselves well for building higher level
36 .\"O locking abstractions such as POSIX mutexes.
37 Linux カーネルは、ユーザ空間で高速なロック機構やセマフォを使用するための
38 基礎的要素として futex ("Fast Userspace muTexes"; 高速ユーザ空間 mutex) を
39 提供している。
40 futex は非常に基本的なもので、 POSIX mutex のような高度なロック機構の概念を
41 構築するのに役立っている。
42 .PP
43 .\"O This page does not set out to document all design decisions
44 .\"O but restricts itself to issues relevant for
45 .\"O application and library development.
46 .\"O Most programmers will in fact not be using futexes directly but
47 .\"O instead rely on system libraries built on them,
48 .\"O such as the NPTL pthreads implementation.
49 このページはすべての設計決定を記述するようにはなっておらず、
50 アプリケーションやライブラリの開発に関係することがらに限っている。
51 実際にはプログラマの多くは直接は futex を扱わないが、その代わり
52 futex に基づいて構築されたシステムライブラリ (例えば NPTL スレッド) に
53 依存することになるだろう。
54 .PP
55 .\"O A futex is identified by a piece of memory which can be
56 .\"O shared between different processes.
57 .\"O In these different processes, it need not have identical addresses.
58 .\"O In its bare form, a futex has semaphore semantics;
59 .\"O it is a counter that can be incremented and decremented atomically;
60 .\"O processes can wait for the value to become positive.
61 futex は異なるプロセス間で共有することのできるメモリ片で識別される。
62 これらの異なるプロセスでは、同じアドレスが付与されている必要はない。
63 裸の姿では futex のセマンティクスはセマフォと同じである。
64 futex は不可分操作で (atomically) インクリメントしたりデクリメントしたりできる
65 カウンタで、プロセスは値が正になるのを待つことができる。
66 .PP
67 .\"O Futex operation is entirely userspace for the noncontended case.
68 .\"O The kernel is only involved to arbitrate the contended case.
69 .\"O As any sane design will strive for noncontention,
70 .\"O futexes are also optimized for this situation.
71 futex の操作は、競合がない場合には完全にユーザ空間で行なわれる。
72 カーネルは競合が起こった場合の仲裁に関与するだけである。
73 良識ある設計では競合が起こらないよう努力するが、
74 futex も競合状態に関して最適化されている。
75 .PP
76 .\"O In its bare form, a futex is an aligned integer which is
77 .\"O only touched by atomic assembler instructions.
78 .\"O Processes can share this integer using
79 .\"O .BR mmap (2),
80 .\"O via shared memory segments or because they share memory space,
81 .\"O in which case the application is commonly called multithreaded.
82 裸の姿では、 futex は不可分なアセンブリ命令でのみ操作される
83 アラインメントの揃った int 型の変数である。
84 複数のプロセスはこの int 型変数を、
85 .BR mmap (2)
86 を用いるか、
87 共有メモリセグメントを介するか、
88 メモリ空間を共有する (この場合、
89 アプリケーションは一般的にマルチ・スレッドであると呼ばれる) か方法で共有する。
90 .\"O .SS "Semantics"
91 .SS "セマンティクス"
92 .PP
93 .\"O Any futex operation starts in userspace,
94 .\"O but it may necessary to communicate with the kernel using the
95 .\"O .BR futex (2)
96 .\"O system call.
97 futex の操作はすべてユーザ空間から始まるが、必要に応じて
98 .BR futex (2)
99 システムコールを用いてカーネルと通信する。
100 .PP
101 .\"O To "up" a futex, execute the proper assembler instructions that
102 .\"O will cause the host CPU to atomically increment the integer.
103 .\"O Afterward, check if it has in fact changed from 0 to 1, in which case
104 .\"O there were no waiters and the operation is done.
105 .\"O This is the noncontended case which is fast and should be common.
106 futex を "up" するには、
107 ホスト CPU に対し int 型変数を不可分操作でインクリメントするような、
108 適切なアセンブリ命令を実行する。
109 そのあと、実際に 0 から 1 に変化したかどうかをチェックし、
110 変化していれば待ちプロセス (waiter) はないということであり、操作は完了する。
111 これは競合のない場合であり、高速でよく起こるはずである。
112 .PP
113 .\"O In the contended case, the atomic increment changed the counter
114 .\"O from \-1  (or some other negative number).
115 .\"O If this is detected, there are waiters.
116 .\"O Userspace should now set the counter to 1 and instruct the
117 .\"O kernel to wake up any waiters using the
118 .\"O .B FUTEX_WAKE
119 .\"O operation.
120 競合がある場合、不可分操作のインクリメントでカウンタは \-1 (または他の負の数)
121 から変化する。これが検出されると、待ちプロセスがあるということである。
122 ユーザ空間ではカウンタを 1 に設定し、
123 .B FUTEX_WAKE
124 を用いてカーネルに待ちプロセスを wake (起床) させるよう指示する。
125 .PP
126 .\"O Waiting on a futex, to "down" it, is the reverse operation.
127 .\"O Atomically decrement the counter and check if it changed to 0,
128 .\"O in which case the operation is done and the futex was uncontended.
129 .\"O In all other circumstances, the process should set the counter to \-1
130 .\"O and request that the kernel wait for another process to up the futex.
131 .\"O This is done using the
132 .\"O .B FUTEX_WAIT
133 .\"O operation.
134 futex の獲得を待つ、すなわち futex を "down" するには反対の操作を行なう。
135 不可分操作でカウンタをデクリメントし、カウンタが 0 に変化したかどうかを
136 チェックする。変化していれば操作は完了し futex は競合していないということである。
137 0 にならなかった場合、プロセスはカウンタを \-1 に設定し、
138 他のプロセスがその futex を up するのを待つようカーネルに要求しなければならない。
139 これは
140 .B FUTEX_WAIT
141 を行なうことで実現される。
142 .PP
143 .\"O The
144 .\"O .BR futex (2)
145 .\"O system call can optionally be passed a timeout specifying how long
146 .\"O the kernel should
147 .\"O wait for the futex to be upped.
148 .\"O In this case, semantics are more complex and the programmer is referred
149 .\"O to
150 .\"O .BR futex (2)
151 .\"O for
152 .\"O more details.
153 .\"O The same holds for asynchronous futex waiting.
154 .BR futex (2)
155 システムコールには、省略可能な引数としてタイムアウトを渡すことができ、
156 カーネルはその futex が up されるのをどれくらいの期間待つべきかを
157 指定することができる。この場合、セマンティクスはもっと複雑になるため、
158 より詳細な情報を得るにはプログラマは
159 .BR futex (2)
160 を参照すること。
161 同じページに非同期の futex 待ちについても記されている。
162 .\"O .SH "VERSIONS"
163 .SH バージョン
164 .PP
165 .\"O Initial futex support was merged in Linux 2.5.7
166 .\"O but with different semantics from those described above.
167 .\"O Current semantics are available from Linux 2.5.40 onward.
168 最初の futex 対応は Linux 2.5.7 で組み込まれたが、
169 上記のセマンティクスとは異なる。
170 現在のセマンティクスは Linux 2.5.40 以降で利用可能である。
171 .\"O .SH "NOTES"
172 .SH 注意
173 .PP
174 .\"O To reiterate, bare futexes are not intended as an easy to use
175 .\"O abstraction for end-users.
176 .\"O Implementors are expected to be assembly literate and to have read
177 .\"O the sources of the futex userspace library referenced
178 .\"O below.
179 再び繰り返しておくが、裸の futex はエンドユーザが容易に使える概念として
180 意図されたものではない。
181 実装者は、アセンブリ言語に慣れており、以下に挙げる futex ユーザ空間ライブラリの
182 ソースを読み終えていることが要求される。
183 .PP
184 .\"O This man page illustrates the most common use of the
185 .\"O .BR futex (2)
186 .\"O primitives: it is by no means the only one.
187 このマニュアルページには
188 .BR futex (2)
189 プリミティブの最も一般的な使用法が
190 記されている。これは決して唯一の使用法ではない。
191 .\"O .\" .SH "AUTHORS"
192 .\" .SH 著者
193 .\" .PP
194 .\"O .\" Futexes were designed and worked on by Hubertus Franke
195 .\"O .\" (IBM Thomas J. Watson Research Center),
196 .\"O .\" Matthew Kirkwood, Ingo Molnar (Red Hat) and
197 .\"O .\" Rusty Russell (IBM Linux Technology Center).
198 .\"O .\" This page written by bert hubert.
199 .\" futex は Hubertus Franke (IBM Thomas J. Watson Research Center) と
200 .\" Matthew Kirkwood 、 Ingo Molnar (Red Hat) 、
201 .\" Rusty Russell (IBM Linux Technology Center) が設計し、検討した。
202 .\" このページは bert hubert が記した。
203 .\"O .SH "SEE ALSO"
204 .SH 関連項目
205 .BR futex (2)
206 .PP
207 .\"O .IR "Fuss, Futexes and Furwocks: Fast Userlevel Locking in Linux"
208 .\"O (proceedings of the Ottawa Linux Symposium 2002),
209 .\"O futex example library, futex-*.tar.bz2
210 .\"O <URL:ftp://ftp.kernel.org/pub/linux/kernel/people/rusty/>.
211 .IR "Fuss, Futexes and Furwocks: Fast Userlevel Locking in Linux"
212 (proceedings of the Ottawa Linux Symposium 2002),
213 futex の使用例ライブラリ, futex-*.tar.bz2
214 <URL:ftp://ftp.kernel.org/pub/linux/kernel/people/rusty/>.