1 .\" Page by b.hubert - may be freely modified and distributed
3 .\" Niki A. Rahimi (LTC Security Development, narahimi@us.ibm.com)
4 .\" added ERRORS section.
6 .\" Modified 2004-06-17 mtk
7 .\" Modified 2004-10-07 aeb, added FUTEX_REQUEUE, FUTEX_CMP_REQUEUE
9 .\" FIXME See also https://bugzilla.kernel.org/show_bug.cgi?id=14303
10 .\" 2.6.14 adds FUTEX_WAKE_OP
11 .\" 2.6.18 adds (Ingo Molnar) priority inheritance support:
12 .\" FUTEX_LOCK_PI, FUTEX_UNLOCK_PI, and FUTEX_TRYLOCK_PI. These need
13 .\" to be documented in the manual page. Probably there is sufficient
14 .\" material in the kernel source file Documentation/pi-futex.txt.
15 .\" 2.6.25 adds FUTEX_WAKE_BITSET, FUTEX_WAIT_BITSET
17 .\" Japanese Version Copyright(C) 2003 Suzuki Takashi
18 .\" all rights reserved.
19 .\" Translated Fri Oct 24 10:37:10 JST 2003
20 .\" by Suzuki Takashi.
21 .\" Updated & Modified Sat Feb 5 14:28:53 JST 2005
22 .\" by Yuichi SATO <ysato444@yahoo.co.jp>, LDP v2.01
23 .\" Updated & Modified Wed Jan 3 04:51:22 JST 2007 by Yuichi SATO, LDP v2.43
25 .\"WORD: integer int 型変数
30 .TH FUTEX 2 2010-08-29 "Linux" "Linux Programmer's Manual"
33 .\"O futex \- Fast Userspace Locking system call
34 futex \- 高速ユーザ空間ロック機構のシステムコール
39 .B "#include <linux/futex.h>"
40 .B "#include <sys/time.h>"
42 .BI "int futex(int *" uaddr ", int " op ", int " val \
43 ", const struct timespec *" timeout ,
45 .BI " int *" uaddr2 ", int " val3 );
46 .\" int *? void *? u32 *?
48 .\"O .SH "DESCRIPTION"
53 .\"O system call provides a method for
54 .\"O a program to wait for a value at a given address to change, and a
55 .\"O method to wake up anyone waiting on a particular address (while the
56 .\"O addresses for the same memory in separate processes may not be
57 .\"O equal, the kernel maps them internally so the same memory mapped in
58 .\"O different locations will correspond for
61 .\"O This system call is typically used to
62 .\"O implement the contended case of a lock in shared memory, as
67 指定したアドレスの値が変更されるのをプログラムが待つ手段や
68 特定のアドレスに対して待機中のプロセスを wake (起床) させる手段を提供する
69 (プロセスが異なれば同じメモリに対するアドレスも同じではないかもしれないが、
70 カーネルは異なる位置にマップされた同じメモリを
76 共有メモリ中のロックが競合する場合の処理を実装するのに用いられる。
80 .\"O operation did not finish uncontended in userspace, a call needs to be made
81 .\"O to the kernel to arbitrate.
82 .\"O Arbitration can either mean putting the calling
83 .\"O process to sleep or, conversely, waking a waiting process.
85 の操作がユーザ空間で競合なく完了しなかった場合、
86 カーネルに仲裁させるためにシステムコールを呼ぶ必要がある。
87 仲裁というのは、呼び出しプロセスを sleep (起床待ち) させたり、反対に
88 待ちプロセスを wake させたりすることを意味する。
90 .\"O Callers of this function are expected to adhere to the semantics as set out in
93 .\"O semantics involve writing nonportable assembly instructions, this in turn
94 .\"O probably means that most users will in fact be library authors and not
95 .\"O general application developers.
98 に記述されているセマンティクスに忠実であることが要求される。
99 このセマンティクスには移植不可能なアセンブリ命令を書くことが含まれる。
100 このことは言い換えると futex のユーザのほとんどは実際はライブラリの作者であり、
101 一般アプリケーションの開発者ではないということである。
105 .\"O argument needs to point to an aligned integer which stores the counter.
106 .\"O The operation to execute is passed via the
108 .\"O argument, along with a value
112 アラインメントの揃った int 型変数を指している必要がある。
119 .\"O Five operations are currently defined:
120 現在のところ 5 つの操作が定義されている:
123 .\"O This operation atomically verifies that the futex address
125 .\"O still contains the value
127 .\"O and sleeps awaiting
129 .\"O on this futex address.
132 .\"O argument is non-NULL, its contents describe the maximum
133 .\"O duration of the wait, which is infinite otherwise.
143 がまだ格納されているかどうかを不可分操作で検証し、
149 引き数が NULL でない場合、その内容は
150 待ち時間の最大値を表す。NULL の場合は無限大を表す。
159 .\"O this call is executed if decrementing the count gave a negative value
160 .\"O (indicating contention), and will sleep until another process releases
161 .\"O the futex and executes the
166 カウントのデクリメントで負の値 (競合を表す) になった場合に実行され、
172 .\"O This operation wakes at most \fIval\fP
173 .\"O processes waiting on this futex address (i.e., inside
174 .\"O .BR FUTEX_WAIT ).
175 この操作では指定した futex アドレスに対して待ち状態の
178 中の) 最大 \fIval\fP 個のプロセスを wake させる。
193 .\"O this is executed if incrementing
194 .\"O the count showed that there were waiters, once the futex value has been set
195 .\"O to 1 (indicating that it is available).
196 \fBfutex\fR(4) に照らし合わせると、
198 カウントのインクリメントで待ちプロセスがあると判明し、
199 futex 値が 1 に設定された (利用可能であることを表す) 場合に実行される。
201 .\"O .BR FUTEX_FD " (present up to and including Linux 2.6.25)"
202 .BR FUTEX_FD " (Linux 2.6.25 以前)"
203 .\"O To support asynchronous wakeups, this operation associates a file descriptor
205 .\"O .\" , suitable for .BR poll (2).
206 .\"O If another process executes a
207 .\"O .BR FUTEX_WAKE ,
208 .\"O the process will receive the signal number that was passed in
209 .\"O number that was passed in
211 .\"O The calling process must close the returned file descriptor after use.
212 非同期の wake に対応するため、この操作はファイルディスクリプタを futex に
220 で渡されたシグナル番号のシグナルを受信する。
221 呼び出しプロセスは使用後、返されたファイルディスクリプタを
235 .\"O To prevent race conditions, the caller should test if the futex has
236 .\"O been upped after
239 競合状態を防止するため、呼び出しプロセスは
242 futex が up されたかどうかを確認しなければならない。
244 .\" FIXME . Check that this flag does eventually get removed.
245 .\"O Because it was inherently racy,
247 .\"O has been removed from Linux 2.6.26 onward.
250 Linux 2.6.26 以降で削除されている。
252 .\"O .BR FUTEX_REQUEUE " (since Linux 2.5.70)"
253 .BR FUTEX_REQUEUE " (Linux 2.5.70 以降)"
254 .\"O This operation was introduced in order to avoid a "thundering herd" effect
257 .\"O is used and all processes woken up need to acquire another
259 .\"O This call wakes up
261 .\"O processes, and requeues all other waiters on the futex at address
265 が使われていて、かつ wake されている全てのプロセスが
266 他の futex を取得する必要がある場合に、
267 「獣の群れの暴走 (thundering herd)」効果を避けるために導入された。
272 で futex を待っている他の全てのプロセスを再度キューにいれる。
284 .\"O .BR FUTEX_CMP_REQUEUE " (since Linux 2.6.7)"
285 .BR FUTEX_CMP_REQUEUE " (Linux 2.6.7 以降)"
286 .\"O There was a race in the intended use of
287 .\"O .BR FUTEX_REQUEUE ,
289 .\"O .B FUTEX_CMP_REQUEUE
291 .\"O This is similar to
292 .\"O .BR FUTEX_REQUEUE ,
293 .\"O but first checks whether the location
295 .\"O still contains the value
298 .\"Osato: intended がよく分からない。
310 がまだ保持されているかを最初にチェックする。
311 .\"O If not, the operation fails with the error
321 .\"O .SH "RETURN VALUE"
324 .\"O Depending on which operation was executed,
325 .\"O the returned value for a successful call can have differing meanings.
330 .\"O Returns 0 if the process was woken by a
333 .\"O In case of timeout,
334 .\"O the operation fails with the error
336 .\"O If the futex was not equal to the expected value,
337 .\"O the operation fails with the error
338 .\"O .BR EWOULDBLOCK .
341 .\"O or other spurious wakeups cause
343 .\"O to fail with the error
347 の呼び出しで wake すると 0 を返す。
351 futex が指定された値と等しくない場合、
357 参照) 他の偽の wake があった場合には、エラー
362 .\"O Returns the number of processes woken up.
366 .\"O Returns the new file descriptor associated with the futex.
367 futex に関連づけられた新たなファイルディスクリプタを返す。
370 .\"O Returns the number of processes woken up.
374 .\"O Returns the number of processes woken up.
377 .\"O In the event of an error, all operations return \-1, and set
379 .\"O to indicate the error.
380 エラーの場合、全ての操作で \-1 が返り、
387 .\"O No read access to futex memory.
388 futex メモリに読み込みアクセス権がなかった。
391 .\"O .B FUTEX_CMP_REQUEUE
392 .\"O found an unexpected futex value.
393 .\"O (This probably indicates a race;
405 .\"O Error in getting
407 .\"O information from userspace.
413 .\"O An operation was not defined or error in page alignment.
414 操作が定義されていない。またはページ・アラインメントでエラーが発生した。
417 .\"O The system limit on the total number of open files has been reached.
418 オープンされているファイルの総数がシステムの制限に達した。
421 .\"O Invalid operation specified in
428 .\"O Initial futex support was merged in Linux 2.5.7 but with different semantics
429 .\"O from what was described above.
430 .\"O A 4-argument system call with the semantics
431 .\"O described in this page was introduced in Linux 2.5.40.
432 .\"O In Linux 2.5.70 one argument
434 .\"O In Linux 2.6.7 a sixth argument was added\(emmessy, especially
435 .\"O on the s390 architecture.
436 最初の futex 対応は Linux 2.5.7 で組み込まれたが、
438 4 つの引き数のここに書かれているセマンティクスを持つ
439 システムコールは、Linux 2.5.40 で導入された。
440 Linux 2.5.70 では 1 つの引き数が追加された。
441 Linux 2.6.7 では 6 番目の引き数が追加された。
442 これは汚く、s390 アーキテクチャ上の特別のものである。
443 .\"O .SH "CONFORMING TO"
445 .\"O This system call is Linux-specific.
446 このシステムコールは Linux 独自である。
450 .\"O To reiterate, bare futexes are not intended as an easy-to-use abstraction
452 .\"O (There is no wrapper function for this system call in glibc.)
453 .\"O Implementors are expected to be assembly literate and to have
454 .\"O read the sources of the futex userspace library referenced below.
455 繰り返すが、裸の futex はエンドユーザが容易に使うことのできる概念として
457 (glibc にはこのシステムコールに対するラッパー関数はない)。
458 実装者は、アセンブリ言語に慣れており、以下に挙げる futex ユーザ空間ライブラリの
460 .\"O .\" .SH "AUTHORS"
463 .\"O .\" Futexes were designed and worked on by
464 .\"O .\" Hubertus Franke (IBM Thomas J. Watson Research Center),
465 .\"O .\" Matthew Kirkwood, Ingo Molnar (Red Hat)
466 .\"O .\" and Rusty Russell (IBM Linux Technology Center).
467 .\"O .\" This page written by bert hubert.
468 .\" futex は Hubertus Franke (IBM Thomas J. Watson Research Center),
469 .\" Matthew Kirkwood, Ingo Molnar (Red Hat),
470 .\" Rusty Russell (IBM Linux Technology Center) が設計し、作成した。
471 .\" このページは bert hubert が記した。
476 \fIFuss, Futexes and Furwocks: Fast Userlevel Locking in Linux\fP
477 (proceedings of the Ottawa Linux Symposium 2002), online at
479 http://kernel.org/doc/ols/2002/ols2002-pages-479-495.pdf
481 .\"O Futex example library, futex-*.tar.bz2 at
482 futex の使用例ライブラリ, futex-*.tar.bz2
484 ftp://ftp.nl.kernel.org/pub/linux/kernel/people/rusty/.