OSDN Git Service

(split) LDP: Restore and add Copyrights for draft pages
[linuxjm/LDP_man-pages.git] / draft / man7 / sem_overview.7
1 .\" t
2 .\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein.  The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .\"*******************************************************************
27 .\"
28 .\" This file was generated with po4a. Translate the source file.
29 .\"
30 .\"*******************************************************************
31 .\"
32 .\" Japanese Version Copyright (c) 2006 Akihiro MOTOKI all rights reserved.
33 .\" Translated 2006-04-18, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
34 .\" Updated 2008-08-07, Akihiro MOTOKI, LDP v3.05
35 .\" Updated 2009-02-23, Akihiro MOTOKI, LDP v3.19
36 .\"
37 .TH SEM_OVERVIEW 7 2012\-05\-13 Linux "Linux Programmer's Manual"
38 .SH 名前
39 sem_overview \- POSIX セマフォの概要
40 .SH 説明
41 POSIX セマフォを使用すると、プロセスやスレッド間でその動作を 同期させることができる。
42
43 セマフォは整数であり、その値は決して 0 未満になることは許されない。 セマフォに対してできる操作は 2 つである: セマフォ値を 1 増やす
44 (\fBsem_post\fP(3)); セマフォ値を 1 減らす (\fBsem_wait\fP(3))。 セマフォの値がすでに 0 の場合、セマフォ値が 0
45 より大きくなるまで \fBsem_wait\fP(3)  操作は停止 (block) する。
46
47 POSIX セマフォには、名前付きセマフォ (named semaphore) と 名前なしセマフォ (unnamed semaphore) の
48 2つの形がある。
49 .TP 
50 \fB名前付きセマフォ\fP
51 .\" glibc allows the initial slash to be omitted, and makes
52 .\" multiple initial slashes equivalent to a single slash.
53 .\" This differs from the implementation of POSIX message queues.
54 .\" glibc allows subdirectory components in the name, in which
55 .\" case the subdirectory tree must exist under /dev/shm, and
56 .\" the fist subdirectory component must exist as the name
57 .\" sem.name, and all of the subdirectory components must allow the
58 .\" required permissions if a user wants to create a semaphore
59 .\" object in a subdirectory.
60 名前付きセマフォは \fI/somename\fP という形式の名前で識別される。 その名前は、最大で \fBNAME_MAX\fP\fI\-4\fP (すなわち 251)
61 文字の NULL 終端された文字列で、 スラッシュで始まり、スラッシュ以外の文字が 1 文字以上続く形式である。 \fBsem_open\fP(3)
62 に同じ名前を渡すことにより、2 つのプロセス間で同じ名前のセマフォ に対し操作を行うことができる。
63
64 \fBsem_open\fP(3)  関数は、新しい名前付きセマフォを作成するか、既に存在する名前付き セマフォをオープンする。 セマフォをオープンした後は、
65 \fBsem_post\fP(3)  と \fBsem_wait\fP(3)  を使ってセマフォを操作できる。 プロセスがセマフォの使用を終えた際は、
66 \fBsem_close\fP(3)  を使ってセマフォをクローズできる。 あるセマフォをどのプロセスも使用しなくなると、 \fBsem_unlink\fP(3)
67 を使ってそのセマフォをシステムから削除することができる。
68 .TP 
69 \fB名前なしセマフォ (メモリベース・セマフォ)\fP
70 名前なしセマフォは名前を持たない。その代わり、セマフォは、 複数スレッド間で共有されるメモリ領域、もしくは複数プロセス間で
71 共有されたメモリ領域に置かれる (前者を \fIスレッド共有セマフォ (thread\-shared semaphore)\fP、 後者を
72 \fIプロセス共有セマフォ (process\-shared semaphore)\fP
73 と呼ぶ)。スレッド共有セマフォは、同じプロセス内のスレッド間で共有される メモリ領域、例えば大域変数 (global variable) に配置される。
74 プロセス共有セマフォは、共有メモリ領域 (例えば、 \fBshmget\fP(2)  を使って作成できる System V 共有メモリ・セグメントや
75 \fBshm_open\fP(3)  を使って作成できる POSIX 共有メモリ・オブジェクト)  内に配置しなければならない。
76
77 名前なしセマフォは、使用する前に \fBsem_init\fP(3)  を使って初期化しなければならない。 セマフォは \fBsem_post\fP(3)  と
78 \fBsem_wait\fP(3)  を使って操作できる。 セマフォがもはや必要なくなったときや、 セマフォが置かれているメモリを解放する前には、
79 \fBsem_destroy\fP(3)  を使ってセマフォを破棄すべきである。
80 .PP
81 この節の残りでは、POSIX セマフォの Linux の実装の詳細 について説明する。
82 .SS Versions
83 バージョン 2.6 より前のカーネルでは、Linux は 名前なしのスレッド共有セマフォのみをサポートしていた。 Linux 2.6 と NPTL
84 スレッド実装を提供している glibc が入った システムでは、POSIX セマフォの完全な実装が提供される。
85 .SS 持続性
86 POSIX 名前付きセマフォはカーネル内で保持される。 \fBsem_unlink\fP(3)  で削除されなければ、セマフォは
87 システムがシャットダウンされるまで存在し続ける。
88 .SS リンク
89 POSIX セマフォ API を使用したプログラムは \fIcc \-pthread\fP でコンパイルし、リアルタイムライブラリ \fIlibrt\fP
90 とリンクしなければならない。
91 .SS ファイルシステム経由での名前付きセマフォへのアクセス
92 Linux では、名前付きセマフォは仮想ファイルシステム (virtual file system) 内に \fBsem.\fP\fIsomename\fP
93 という形の名前で作成される。仮想ファイルシステムは通常 \fI/dev/shm\fP 以下にマウントされる。 (これが、セマフォの名前の文字数の上限が
94 \fBNAME_MAX\fP ではなく \fBNAME_MAX\fP\fI\-4\fP となっている理由である。)
95
96 Linux 2.6.19 以降では、このディレクトリ配下のファイルに対して ACL を
97 設定でき、オブジェクトへの許可をユーザ単位、グループ単位で制御することが できる。
98 .SH 準拠
99 POSIX.1\-2001.
100 .SH 注意
101 System V セマフォ (\fBsemget\fP(2), \fBsemop\fP(2)  など) は古いセマフォ API である。 POSIX セマフォは
102 System V よりも 簡単で、うまく設計されたインタフェースを提供している。 一方で、POSIX セマフォは System V セマフォと比べると
103 利用できるシステムが少ない (特に、古いシステムでは少ない)。
104 .SH 例
105 各種の POSIX セマフォ関数を使用した例が \fBsem_wait\fP(3)  に記載されている。
106 .SH 関連項目
107 \fBsem_close\fP(3), \fBsem_destroy\fP(3), \fBsem_getvalue\fP(3), \fBsem_init\fP(3),
108 \fBsem_open\fP(3), \fBsem_post\fP(3), \fBsem_unlink\fP(3), \fBsem_wait\fP(3),
109 \fBpthreads\fP(7)
110 .SH この文書について
111 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.53 の一部
112 である。プロジェクトの説明とバグ報告に関する情報は
113 http://www.kernel.org/doc/man\-pages/ に書かれている。