'\" t .\" Hey Emacs! This file is -*- nroff -*- source. .\" .\" Copyright (C) 2006 Michael Kerrisk .\" .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" .\" Japanese Version Copyright (c) 2006 Akihiro MOTOKI all rights reserved. .\" Translated 2006-04-18, Akihiro MOTOKI .\" .TH SEM_INIT 3 2008-07-27 "Linux" "Linux Programmer's Manual" .\"O .SH NAME .SH 名前 .\"O sem_init \- initialize an unnamed semaphore sem_init \- 名前なしセマフォを初期化する .\"O .SH SYNOPSIS .SH 書式 .nf .B #include .sp .BI "int sem_init(sem_t *" sem ", int " pshared ", unsigned int " value ); .fi .sp .\"O Link with \fI\-lrt\fP or \fI\-pthread\fP. \fI\-lrt\fP または \fI\-pthread\fP でリンクする。 .\"O .SH DESCRIPTION .SH 説明 .\"O .BR sem_init () .\"O initializes the unnamed semaphore at the address pointed to by .\"O .IR sem . .\"O The .\"O .I value .\"O argument specifies the initial value for the semaphore. .BR sem_init () は、 .I sem が指すアドレスにある名前なしセマフォを初期化する。 .I value 引き数はそのセマフォの初期値を指定する。 .\"O The .\"O .I pshared .\"O argument indicates whether this semaphore is to be shared .\"O between the threads of a process, or between processes. .I pshared 引き数は、このセマフォがプロセス内のスレッド間で共有されるのか、 プロセス間で共有されるのか、を示す。 .\"O If .\"O .I pshared .\"O has the value 0, .\"O then the semaphore is shared between the threads of a process, .\"O and should be located at some address that is visible to all threads .\"O (e.g., a global variable, or a variable allocated dynamically on .\"O the heap). .I pshared が 0 の場合、セマフォはプロセス内のスレッド間で共有される。 セマフォはすべてのスレッドから参照可能なアドレスに配置すべきである (例えば、大域変数や、ヒープ上に動的に割り当てられた変数など)。 .\"O If .\"O .I pshared .\"O is nonzero, then the semaphore is shared between processes, .\"O and should be located in a region of shared memory (see .\"O .BR shm_open (3), .\"O .BR mmap (2), .\"O and .\"O .BR shmget (2)). .\"O (Since a child created by .\"O .BR fork (2) .\"O inherits its parent's memory mappings, it can also access the semaphore.) .\"O Any process that can access the shared memory region .\"O can operate on the semaphore using .\"O .BR sem_post (3), .\"O .BR sem_wait (3), .\"O etc. .I pshared が 0 以外の場合、セマフォはプロセス間で共有される。セマフォは 共有メモリ領域に配置すべきである .RB ( shm_open (3), .BR mmap (2), .BR shmget (2) 参照)。 .RB ( fork (2) で生成された子プロセスは親プロセスのメモリマッピングを継承するため、 子プロセスもセマフォにアクセスできる。) 共有メモリ領域にアクセスできるプロセスならば、どのプロセスでも .BR sem_post (3) や .BR sem_wait (3) などを使ってセマフォを操作できる。 .\"O Initializing a semaphore that has already been initialized .\"O results in undefined behavior. すでに初期化済のセマフォを初期化した場合の挙動は定義されていない。 .\"O .SH RETURN VALUE .SH 返り値 .\"O .BR sem_init () .\"O returns 0 on success; .\"O on error, \-1 is returned, and .\"O .I errno .\"O is set to indicate the error. 成功すると、 .BR sem_init () は 0 を返す。エラーの場合、\-1 を返し、 .I errno にエラーを示す値をセットする。 .\"O .SH ERRORS .SH エラー .TP .B EINVAL .\"O .I value .\"O exceeds .\"O .BR SEM_VALUE_MAX . .I value が .B SEM_VALUE_MAX を超えている。 .TP .B ENOSYS .\"O .I pshared .\"O is nonzero, .\"O but the system does not support process-shared semaphores (see .\"O .BR sem_overview (7)). .I pshared が 0 以外だが、システムがプロセス共有セマフォをサポートしていない .RB ( sem_overview (7) 参照)。 .\"O .SH CONFORMING TO .SH 準拠 POSIX.1-2001. .\"O .SH NOTES .SH 注意 .\"O Bizarrely, POSIX.1-2001 does not specify the value that should .\"O be returned by a successful call to .\"O .BR sem_init (). .\"O POSIX.1-2008 rectifies this, specifying the zero return on success. 妙なことに、POSIX.1-2001 は .BR sem_init () が成功した場合に返すべき値を規定していない。 POSIX.1-2008 ではこれが修正され、成功時には 0 を返すことが規定された。 .\"O .SH "SEE ALSO" .SH 関連項目 .BR sem_destroy (3), .BR sem_post (3), .BR sem_wait (3), .BR sem_overview (7)