1 .\" This page is made available under the MIT license.
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>.
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.
19 .TH FUTEX 7 2002-12-31 "Linux" "Linux Programmer's Manual"
22 .\"O futex \- Fast Userspace Locking
27 .B #include <linux/futex.h>
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) を
40 futex は非常に基本的なもので、 POSIX mutex のような高度なロック機構の概念を
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 スレッド) に
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 カウンタで、プロセスは値が正になるのを待つことができる。
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 も競合状態に関して最適化されている。
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
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 型の変数である。
89 アプリケーションは一般的にマルチ・スレッドであると呼ばれる) か方法で共有する。
93 .\"O Any futex operation starts in userspace,
94 .\"O but it may necessary to communicate with the kernel using the
97 futex の操作はすべてユーザ空間から始まるが、必要に応じて
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.
107 ホスト CPU に対し int 型変数を不可分操作でインクリメントするような、
109 そのあと、実際に 0 から 1 に変化したかどうかをチェックし、
110 変化していれば待ちプロセス (waiter) はないということであり、操作は完了する。
111 これは競合のない場合であり、高速でよく起こるはずである。
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
120 競合がある場合、不可分操作のインクリメントでカウンタは \-1 (または他の負の数)
121 から変化する。これが検出されると、待ちプロセスがあるということである。
124 を用いてカーネルに待ちプロセスを wake (起床) させるよう指示する。
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
134 futex の獲得を待つ、すなわち futex を "down" するには反対の操作を行なう。
135 不可分操作でカウンタをデクリメントし、カウンタが 0 に変化したかどうかを
136 チェックする。変化していれば操作は完了し futex は競合していないということである。
137 0 にならなかった場合、プロセスはカウンタを \-1 に設定し、
138 他のプロセスがその futex を up するのを待つようカーネルに要求しなければならない。
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
153 .\"O The same holds for asynchronous futex waiting.
155 システムコールには、省略可能な引数としてタイムアウトを渡すことができ、
156 カーネルはその futex が up されるのをどれくらいの期間待つべきかを
157 指定することができる。この場合、セマンティクスはもっと複雑になるため、
161 同じページに非同期の futex 待ちについても記されている。
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 で組み込まれたが、
170 現在のセマンティクスは Linux 2.5.40 以降で利用可能である。
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
179 再び繰り返しておくが、裸の futex はエンドユーザが容易に使える概念として
181 実装者は、アセンブリ言語に慣れており、以下に挙げる futex ユーザ空間ライブラリの
184 .\"O This man page illustrates the most common use of the
186 .\"O primitives: it is by no means the only one.
190 記されている。これは決して唯一の使用法ではない。
191 .\"O .\" .SH "AUTHORS"
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 が記した。
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/>.