.\" Copyright 1993 Giorgio Ciucci (giorgio@crcc.it) .\" .\" 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. .\" .\" Modified 1996-10-22, Eric S. Raymond .\" Modified 2002-01-08, Michael Kerrisk .\" Modified 2003-04-28, Ernie Petrides .\" Modified 2004-05-27, Michael Kerrisk .\" Modified, 11 Nov 2004, Michael Kerrisk .\" Language and formatting clean-ups .\" Added notes on /proc files .\" 2005-04-08, mtk, Noted kernel version numbers for semtimedop() .\" 2007-07-09, mtk, Added an EXAMPLE code segment. .\" .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya .\" all rights reserved. .\" Translated 1997-02-23, HANATAKA Shinya .\" Updated 2003-02-09, Kentaro Shirakata .\" Updated 2003-09-12, Kentaro Shirakata .\" Updated 2005-03-01, Akihiro MOTOKI .\" Updated 2005-04-17, Akihiro MOTOKI .\" Updated 2005-09-06, Akihiro MOTOKI .\" Updated 2007-05-01, Akihiro MOTOKI, LDP v2.46 .\" .\"WORD: semaphore セマフォ .\"WORD: member メンバー .\"WORD: process プロセス .\"WORD: system call システムコール .\"WORD: undo アンドゥ .\"WORD: signal シグナル .\"WORD: catch 捕獲(catch) .\"WORD: process-ID プロセスID .\"WORD: policy 方針 .\"WORD: implement 実装 .\"WORD: queue キュー .\"WORD: free 解放(free). .\"WORD: memory メモリ .\"WORD: anonymous structure 無名構造体 .\"WORD: time limit 制限時間 \" .TH SEMOP 2 2008-10-04 "Linux" "Linux Programmer's Manual" .\"O .SH NAME .SH 名前 .\"O semop, semtimedop \- semaphore operations semop, semtimedop \- セマフォの操作 .\"O .SH SYNOPSIS .SH 書式 .nf .B #include .B #include .B #include .sp .BI "int semop(int " semid ", struct sembuf *" sops ", unsigned " nsops ); .sp .BI "int semtimedop(int " semid ", struct sembuf *" sops ", unsigned " nsops , .BI " struct timespec *" timeout ); .fi .sp .in -4n .\"O Feature Test Macro Requirements for glibc (see .\"O .BR feature_test_macros (7)): glibc 向けの機能検査マクロの要件 .RB ( feature_test_macros (7) 参照): .in .sp .BR semtimedop (): _GNU_SOURCE .\"O .SH DESCRIPTION .SH 説明 .\"O Each semaphore in a semaphore set has the following associated values: セマフォ集合 (semaphore set) のメンバーの各セマフォは 以下の関連情報を持っている: .sp .in +4n .nf .\"O unsigned short semval; /* semaphore value */ .\"O unsigned short semzcnt; /* # waiting for zero */ .\"O unsigned short semncnt; /* # waiting for increase */ .\"O pid_t sempid; /* process that did last op */ unsigned short semval; /* セマフォ値 */ unsigned short semzcnt; /* ゼロを待つプロセス数 */ unsigned short semncnt; /* 増加を待つプロセス数 */ pid_t sempid; /* 最後に操作を行なったプロセス */ .sp .in -4n .fi .\"O .BR semop () .\"O performs operations on selected semaphores in the set indicated by .\"O .IR semid . .BR semop () は .I semid で指定されたセマフォ集合の選択されたセマフォに対して操作を行う。 .\"O Each of the .\"O .I nsops .\"O elements in the array pointed to by .\"O .I sops .\"O specifies an operation to be performed on a single semaphore. .\"O The elements of this structure are of type .\"O .IR "struct sembuf" , .\"O containing the following members: .I sops は .I nsops 個の要素の配列を指し、配列の各要素は個々のセマフォに 対する操作を示す。その型は .I struct sembuf で、次のメンバを持つ: .sp .in +4n .nf .\"O unsigned short sem_num; /* semaphore number */ .\"O short sem_op; /* semaphore operation */ .\"O short sem_flg; /* operation flags */ unsigned short sem_num; /* セマフォ番号 */ short sem_op; /* セマフォ操作 */ short sem_flg; /* 操作フラグ */ .sp .in -4n .fi .\"O Flags recognized in .\"O .I sem_flg .\"O are .\"O .B IPC_NOWAIT .\"O and .\"O .BR SEM_UNDO . .\"O If an operation specifies .\"O .BR SEM_UNDO , .\"O it will be automatically undone when the process terminates. .I sem_flg には .B IPC_NOWAIT と .B SEM_UNDO が設定できる。 .B SEM_UNDO が指定された操作は、そのプロセスが終了した時に自動的に取り消される。 .PP .\"O The set of operations contained in .\"O .I sops .\"O is performed in .\"O .IR "array order" , .\"O and .\"O .IR atomically , .\"O that is, the operations are performed either as a complete unit, .\"O or not at all. .I sops に含まれる操作の集合は、 .I "配列の順序" で、 .I アトミックに 実行される。 すなわち、全ての操作が完全に実行されるか、全く実行されないかの どちらかとなる。 .\"O The behavior of the system call if not all operations can be .\"O performed immediately depends on the presence of the .\"O .B IPC_NOWAIT .\"O flag in the individual .\"O .I sem_flg .\"O fields, as noted below. 全ての操作が直ちに実行できない場合のこのシステムコールの振る舞いは 個々の操作の .I sem_flg フィールドに .B IPC_NOWAIT が存在するかによって決まり、後述のようになる。 .\"O Each operation is performed on the .\"O .IR sem_num \-th .\"O semaphore of the semaphore set, where the first semaphore of the set .\"O is numbered 0. それぞれの操作はセマフォ集合の .IR sem_num 番目 のセマフォに対して実行される。セマフォ集合の最初のセマフォには 番号 0 が振られる。 .\"O There are three types of operation, distinguished by the value of .\"O .IR sem_op . そして操作は三種類あり、 .I sem_op の値で区別される。 .PP .\"O If .\"O .I sem_op .\"O is a positive integer, the operation adds this value to .\"O the semaphore value .\"O .RI ( semval ). .\"O Furthermore, if .\"O .B SEM_UNDO .\"O is specified for this operation, the system updates the process undo count .\"O .RI ( semadj ) .\"O for this semaphore. .\"O This operation can always proceed \(em it never forces a process to wait. .\"O The calling process must have alter permission on the semaphore set. .I sem_op が正の整数の場合、操作としてその値をセマフォの値 .RI ( semval ) に加える。さらにこの操作に .B SEM_UNDO が指定されている場合は、システムはこのセマフォの プロセス・アンドゥ数 .RI ( semadj ) を更新する。 この操作は必ず実行でき、プロセスの停止は起こらない。 呼び出し元プロセスは対象のセマフォ集合を変更する許可がなければならない。 .PP .\"O If .\"O .I sem_op .\"O is zero, the process must have read permission on the semaphore .\"O set. .\"O This is a "wait-for-zero" operation: if .\"O .I semval .\"O is zero, the operation can immediately proceed. .I sem_op が 0 の場合、「ゼロまで待つ」操作である。この場合、プロセスは そのセマフォ集合に対する読み込み許可がなければならない。 .I semval が 0 ならば、操作は直ちに行われる。 .\"O Otherwise, if .\"O .B IPC_NOWAIT .\"O is specified in .\"O .IR sem_flg , .\"O .BR semop () .\"O fails with .\"O .I errno .\"O set to .\"O .B EAGAIN .\"O (and none of the operations in .\"O .I sops .\"O is performed). .I semval が 0 でない場合、 .I sem_flg に .B IPC_NOWAIT が指定されていれば、 .BR semop () は失敗し、 .B errno に .B EAGAIN が設定される (このとき .I sops に対する操作は全く実行されない)。 .\"O Otherwise .\"O .I semzcnt .\"O (the count of processes waiting until this semaphore's value becomes zero) .\"O is incremented by one and the process sleeps until .\"O one of the following occurs: .I sem_flg に .B IPC_NOWAIT が指定されていない場合、 .I semzcnt (セマフォ値が 0 になるのを待っているプロセスの数) を 1 増加させて、 以下のいずれかが起こるまでプロセスを停止 (sleep) する。 .IP \(bu 3 .\"O .I semval .\"O becomes 0, at which time the value of .\"O .I semzcnt .\"O is decremented. .I semval が 0 になった: このとき .I semval の値は 1 減算される。 .IP \(bu .\"O The semaphore set .\"O is removed: .\"O .BR semop () .\"O fails, with .\"O .I errno .\"O set to .\"O .BR EIDRM . セマフォ集合が削除された: このとき .BR semop () は失敗し、 .I errno に .B EIDRM が設定される。 .IP \(bu .\"O The calling process catches a signal: .\"O the value of .\"O .I semzcnt .\"O is decremented and .\"O .BR semop () .\"O fails, with .\"O .I errno .\"O set to .\"O .BR EINTR . 呼び出し元プロセスがシグナルを捕獲した: このとき .I semzcnt の値は 1 減算され、 .BR semop () は失敗し .I errno に .B EINTR が設定される。 .IP \(bu .\"O The time limit specified by .\"O .I timeout .\"O in a .\"O .BR semtimedop () .\"O call expires: .\"O .BR semop () .\"O fails, with .\"O .I errno .\"O set to .\"O .BR EAGAIN . .\" motoki: semop () は semtimedop () の間違い? .BR semtimedop () の .I timeout で指定された制限時間が経過した: このとき .BR semtimedop () は失敗し、 .I errno に .B EAGAIN が設定される。 .PP .\"O If .\"O .I sem_op .\"O is less than zero, the process must have alter permission on the .\"O semaphore set. .\"O If .\"O .I semval .\"O is greater than or equal to the absolute value of .\"O .IR sem_op , .\"O the operation can proceed immediately: .\"O the absolute value of .\"O .I sem_op .\"O is subtracted from .\"O .IR semval , .\"O and, if .\"O .B SEM_UNDO .\"O is specified for this operation, the system updates the process undo count .\"O .RI ( semadj ) .\"O for this semaphore. .I sem_op が 0 未満の場合、プロセスにはそのセマフォ集合を変更する許可がなければ ならない。 .I semval が .I sem_op の絶対値以上の場合は、操作は直ちに実行される: .I semval から .I sem_op の絶対値が減算される。 さらに、この操作に .B SEM_UNDO が指定されている場合は、このセマフォのプロセス・アンドゥ数 .RI ( semadj ) を更新する。 .\"O If the absolute value of .\"O .I sem_op .\"O is greater than .\"O .IR semval , .\"O and .\"O .B IPC_NOWAIT .\"O is specified in .\"O .IR sem_flg , .\"O .BR semop () .\"O fails, with .\"O .I errno .\"O set to .\"O .B EAGAIN .\"O (and none of the operations in .\"O .I sops .\"O is performed). .I semval が .I sem_op の絶対値より小さく、 .I sem_flg に .B IPC_NOWAIT が指定された場合は、 .BR semop () は失敗し、 .I errno に .B EAGAIN が設定される (このとき .I sops の操作は全く実行されない)。 .\"O Otherwise .\"O .I semncnt .\"O (the counter of processes waiting for this semaphore's value to increase) .\"O is incremented by one and the process sleeps until .\"O one of the following occurs: .B IPC_WAIT が指定されていなければ、 .I semncnt (このセマフォの値が増加するのを待っているプロセス数のカウンタ) を 1 増加させて、以下のいずれかが起こるまでプロセスを停止 (sleep) する。 .IP \(bu 3 .\"O .I semval .\"O becomes greater than or equal to the absolute value of .\"O .IR sem_op , .\"O at which time the value of .\"O .I semncnt .\"O is decremented, the absolute value of .\"O .I sem_op .\"O is subtracted from .\"O .I semval .\"O and, if .\"O .B SEM_UNDO .\"O is specified for this operation, the system updates the process undo count .\"O .RI ( semadj ) .\"O for this semaphore. .I semval が .I sem_op の絶対値以上になった: このとき .I semncnt が 1 減算され、 .I semval から .I sem_op の絶対値が引かれる。 この操作に .B SEM_UNDO が指定されていた場合にはこのセマフォのプロセス・アンドゥ数 .RI ( semadj ) も更新する。 .IP \(bu .\"O The semaphore set is removed from the system: .\"O .BR semop () .\"O fails, with .\"O .I errno .\"O set to .\"O .BR EIDRM . セマフォ集合がシステムから削除された: このとき .BR semop () は失敗し .I errno に .B EIDRM が設定される。 .IP \(bu .\"O The calling process catches a signal: .\"O the value of .\"O .I semncnt .\"O is decremented and .\"O .BR semop () .\"O fails, with .\"O .I errno .\"O set to .\"O .BR EINTR . 呼び出したプロセスがシグナルを捕獲した: このとき .I semncnt が 1 減算され、 .BR semop () は失敗し .I errno に .B EINTR が設定される。 .IP \(bu .\"O The time limit specified by .\"O .I timeout .\"O in a .\"O .BR semtimedop () .\"O call expires: the system call fails, with .\"O .I errno .\"O set to .\"O .BR EAGAIN . .\" motoki: the system call は semtimedop () のこと? .BR semtimedop () の .I timeout で指定された制限時間が経過した: このとき .BR semtimedop () は失敗し、 .I errno に .B EAGAIN が設定される。 .PP .\"O On successful completion, the .\"O .I sempid .\"O value for each semaphore specified in the array pointed to by .\"O .I sops .\"O is set to the process ID of the calling process. 操作が成功した場合、 .I sops が指す配列によって操作対象となった各セマフォの .I sempid メンバーには呼び出したプロセスのプロセス ID が設定される。 .\"O In addition, the .\"O .I sem_otime .\"O .\" and .\"O .\" .I sem_ctime .\"O is set to the current time. さらに .I sem_otime .\" と .\" .I sem_ctime に現在時刻が設定される。 .PP .\"O The function .\"O .BR semtimedop () .\"O behaves identically to .\"O .BR semop () .\"O except that in those cases were the calling process would sleep, .\"O the duration of that sleep is limited by the amount of elapsed .\"O time specified by the .\"O .I timespec .\"O structure whose address is passed in the .\"O .I timeout .\"O argument. .BR semtimedop () 関数の振る舞いは .BR semop () と全く同じだが、 呼び出し元プロセスが停止する場合、停止期間の上限が .I timeout 引き数の指す .I timespec 構造体で指定された時間となる点だけが異なる。 .\"O If the specified time limit has been reached, .\"O .BR semtimedop () .\"O fails with .\"O .I errno .\"O set to .\"O .B EAGAIN .\"O (and none of the operations in .\"O .I sops .\"O is performed). 指定した制限時間に達した場合は、 .BR semtimedop () は失敗し、 .I errno に .B EAGAIN が設定される (このとき .I sops の操作は実行されない)。 .\"O If the .\"O .I timeout .\"O argument is NULL, .\"O then .\"O .BR semtimedop () .\"O behaves exactly like .\"O .BR semop (). .I timeout 引き数が NULL の場合、 .BR semtimedop () 関数の振る舞いは .BR semop () 関数と全く同じになる。 .\"O .SH "RETURN VALUE" .SH 返り値 .\"O If successful .\"O .BR semop () .\"O and .\"O .BR semtimedop () .\"O return 0; .\"O otherwise they return \-1 .\"O with .\"O .I errno .\"O indicating the error. 成功した場合、 .BR semop () と .BR semtimedop () は 0 を返す。そうでなければ \-1 を返し、 エラーを示す .I errno を設定する。 .\"O .SH ERRORS .SH エラー .\"O On failure, .\"O .I errno .\"O is set to one of the following: 失敗した場合、 .I errno に以下のどれかが設定される: .TP .B E2BIG .\"O The argument .\"O .I nsops .\"O is greater than .\"O .BR SEMOPM , .\"O the maximum number of operations allowed per system .\"O call. .I nsops 引き数が .B SEMOPM より大きい。 .B SEMOPM は一回のシステムコールで許される操作の最大個数である。 .TP .B EACCES .\"O The calling process does not have the permissions required .\"O to perform the specified semaphore operations, .\"O and does not have the .\"O .B CAP_IPC_OWNER .\"O capability. 呼び出し元プロセスには指定されたセマフォ操作を行うのに 必要なアクセス許可がなく、 .B CAP_IPC_OWNER ケーパビリティもない。 .TP .B EAGAIN .\"O An operation could not proceed immediately and either .\"O .B IPC_NOWAIT .\"O was specified in .\"O .I sem_flg .\"O or the time limit specified in .\"O .I timeout .\"O expired. 操作を直ちに処理することができず、かつ .I sem_flg に .B IPC_NOWAIT が指定されているか .I timeout で指定された制限時間が経過した。 .TP .B EFAULT .\"O An address specified in either the .\"O .I sops .\"O or the .\"O .I timeout .\"O arguments isn't accessible. 引き数 .I sops か .I timeout が指しているアドレスにアクセスできない。 .TP .B EFBIG .\"O For some operation the value of .\"O .I sem_num .\"O is less than 0 or greater than or equal to the number .\"O of semaphores in the set. ある操作で、 .I sem_num の値が 0 未満か、集合内のセマフォの数以上である。 .TP .B EIDRM .\"O The semaphore set was removed. セマフォ集合が削除された。 .TP .B EINTR .\"O While blocked in this system call, the process caught a signal; see .\"O .BR signal (7). このシステムコールで停止している時にプロセスがシグナルを捕獲した。 .BR single (7) 参照。 .TP .B EINVAL .\"O The semaphore set doesn't exist, or .\"O .I semid .\"O is less than zero, or .\"O .I nsops .\"O has a nonpositive value. セマフォ集合が存在しないか、 .I semid が 0 未満であるか、 .I nsops が正の数でない。 .TP .B ENOMEM .\"O The .\"O .I sem_flg .\"O of some operation specified .\"O .B SEM_UNDO .\"O and the system does not have enough memory to allocate the undo .\"O structure. ある操作で .I sem_flg に .B SEM_UNDO が指定されたが、システムにアンドゥ構造体に割り当てる十分なメモリがない。 .TP .B ERANGE .\"O For some operation .\"O .I sem_op+semval .\"O is greater than .\"O .BR SEMVMX , .\"O the implementation dependent maximum value for .\"O .IR semval . ある操作で .I sem_op+semval が .B SEMVMX より大きい。 .B SEMVMX は .I semval の最大値で、その値は実装依存である。 .\"O .SH VERSIONS .SH バージョン .\"O .BR semtimedop () .\"O first appeared in Linux 2.5.52, .\"O and was subsequently backported into kernel 2.4.22. .BR semtimedop () は Linux 2.5.52 で初めて登場し、 それからカーネル 2.4.22 にも移植された。 .\"O Glibc support for .\"O .BR semtimedop () .\"O first appeared in version 2.3.3. .BR semtimedop () の glibc でのサポートはバージョン 2.3.3 で初めて登場した。 .\"O .SH "CONFORMING TO" .SH 準拠 SVr4, POSIX.1-2001. .\"O .\" SVr4 documents additional error conditions EINVAL, EFBIG, ENOSPC. .\" SVr4 には、追加で EINVAL, EFBIG, ENOSPC のエラー状態についての .\" 記述がある。 .\"O .SH NOTES .SH 注意 .\"O The .\"O .I sem_undo .\"O structures of a process aren't inherited by the child produced by .\"O .BR fork (2), .\"O but they are inherited across an .\"O .BR execve (2) .\"O system call. あるプロセスの .I sem_undo 構造体は .BR fork (2) で生成された子プロセスには継承されないが、 .BR execve (2) システムコールの場合は継承される。 .PP .\"O .BR semop () .\"O is never automatically restarted after being interrupted by a signal handler, .\"O regardless of the setting of the .\"O .B SA_RESTART .\"O flag when establishing a signal handler. .BR semop () はシグナルハンドラによって中断された後に、 決して自動的に再開することはない。 たとえシグナルハンドラの設定時に .B SA_RESTART フラグがセットされていても再開することはない .PP .\"O .I semadj .\"O is a per-process integer which is simply the (negative) count .\"O of all semaphore operations performed specifying the .\"O .B SEM_UNDO .\"O flag. .I semadj はプロセスごとの整数で、 .B SEM_UNDO フラグを設定して実行された全てのセマフォ操作の(負数の)カウンタである。 .\"O When a semaphore's value is directly set using the .\"O .B SETVAL .\"O or .\"O .B SETALL .\"O request to .\"O .BR semctl (2), .\"O the corresponding .\"O .I semadj .\"O values in all processes are cleared. .BR semctl (2) に .B SETVAL または .B SETALL を指定し、セマフォの値が 直接設定された場合には、全てのプロセスにおいて対応する .I semadj の値がクリアされる。 .PP .\"O The \fIsemval\fP, \fIsempid\fP, \fIsemzcnt\fP, and \fIsemnct\fP values .\"O for a semaphore can all be retrieved using appropriate .\"O .BR semctl (2) .\"O calls. あるセマフォの \fIsemval\fP, \fIsempid\fP, \fIsemzcnt\fP, \fIsemnct\fP の値はいずれも、適切な操作を指定して .BR semctl (2) を呼び出すことで取得できる。 .PP .\"O The following limits on semaphore set resources affect the .\"O .BR semop () .\"O call: セマフォ集合のリソースに関する制限のうち、 .BR semop () に影響を及ぼすものを以下に挙げる: .TP .B SEMOPM .\"O Maximum number of operations allowed for one .\"O .BR semop () .\"O call (32) .\"O (on Linux, this limit can be read and modified via the third field of .\"O .IR /proc/sys/kernel/sem ). .\"O .\" This /proc file is not available in Linux 2.2 and earlier -- MTK 一回の .BR semop () で許される操作の最大数 (32)。 (Linux では、この制限値は .I /proc/sys/kernel/sem の第3フィールドに対応し、読み出しも変更もできる)。 .\" この /proc ファイルは Linux 2.2 以前では利用できない -- MTK .TP .B SEMVMX .\"O Maximum allowable value for .\"O .IR semval : .\"O implementation dependent (32767). .I semval が取り得る最大値: 実装依存 (32767)。 .PP .\"O The implementation has no intrinsic limits for .\"O the adjust on exit maximum value .\"O .RB ( SEMAEM ), .\"O the system wide maximum number of undo structures .\"O .RB ( SEMMNU ) .\"O and the per-process maximum number of undo entries system parameters. 以下の値に関しては実装依存の制限はない。 終了時の調整 (adjust on exit) の最大値 .RB ( SEMAEM )、 システム全体のアンドゥ構造体の最大数 .RB ( SEMMNU )、 プロセスあたりのアンドゥ構造体の最大数。 .\"O .SH BUGS .SH バグ .\"O When a process terminates, its set of associated .\"O .I semadj .\"O structures is used to undo the effect of all of the .\"O semaphore operations it performed with the .\"O .B SEM_UNDO .\"O flag. プロセスが終了する際、プロセスに対応する .I semadj の集合を使って、 .B SEM_UNDO フラグ付きで実行された全てのセマフォ操作の影響を取り消す。 .\"O This raises a difficulty: if one (or more) of these semaphore adjustments .\"O would result in an attempt to decrease a semaphore's value below zero, .\"O what should an implementation do? これによりある問題が発生する: これらのセマフォの調整を行っていると、 中にはセマフォの値が 0 未満の値にしようとする場合が出てくる。 このような場合、どのように実装するべきか? .\"O One possible approach would be to block until all the semaphore .\"O adjustments could be performed. .\"O This is however undesirable since it could force process termination to .\"O block for arbitrarily long periods. ひとつの考えられる手法は、全てのセマフォ調整が実行されるまで 停止することである。しかし、この方法ではプロセスの終了が 長時間にわたって停止されることがあるので望ましくない。 しかもどれくらい長時間になるかは分からない。 .\"O Another possibility is that such semaphore adjustments could be ignored .\"O altogether (somewhat analogously to failing when .\"O .B IPC_NOWAIT .\"O is specified for a semaphore operation). 別の選択肢として、このようなセマフォ調整を完全に無視してしまう方法がある (これはセマフォ操作として .B IPC_NOWAIT が指定するのと少し似ている)。 .\"O Linux adopts a third approach: decreasing the semaphore value .\"O as far as possible (i.e., to zero) and allowing process .\"O termination to proceed immediately. Linux は第三の手法を採用している: セマフォの値を出来るだけ (つまり 0 まで) 減少させて、プロセスの終了を直ちに続行できるようにしている。 .\"O In kernels 2.6.x, x <= 10, there is a bug that in some circumstances .\"O prevents a process that is waiting for a semaphore value to become .\"O zero from being woken up when the value does actually become zero. .\"O This bug is fixed in kernel 2.6.11. .\"O .\" The bug report: .\"O .\" http://marc.theaimsgroup.com/?l=linux-kernel&m=110260821123863&w=2 .\"O .\" the fix: .\"O .\" http://marc.theaimsgroup.com/?l=linux-kernel&m=110261701025794&w=2 カーネル 2.6.x (x <= 10) には、ある状況においてセマフォ値が 0 になるのを 待っているプロセスが、セマフォ値が実際に 0 になったときに起床 (wake up) されない、というバグがある。このバグはカーネル 2.6.11 で修正されている。 .\" バグレポート: .\" http://marc.theaimsgroup.com/?l=linux-kernel&m=110260821123863&w=2 .\" 修正: .\" http://marc.theaimsgroup.com/?l=linux-kernel&m=110261701025794&w=2 .\"O .SH EXAMPLE .SH 例 .\"O The following code segment uses .\"O .BR semop () .\"O to atomically wait for the value of semaphore 0 to become zero, .\"O and then increment the semaphore value by one. 以下の部分的なコードは、 セマフォ 0 の値が 0 になるのを待ってから、 セマフォの値を 1 加算する処理を、 .BR semop () を使ってアトミック (atomically) に行う。 .nf struct sembuf sops[2]; int semid; /* Code to set \fIsemid\fP omitted */ sops[0].sem_num = 0; /* Operate on semaphore 0 */ sops[0].sem_op = 0; /* Wait for value to equal 0 */ sops[0].sem_flg = 0; sops[1].sem_num = 0; /* Operate on semaphore 0 */ sops[1].sem_op = 1; /* Increment value by one */ sops[1].sem_flg = 0; if (semop(semid, sops, 2) == \-1) { perror("semop"); exit(EXIT_FAILURE); } .fi .\"O .SH "SEE ALSO" .SH 関連項目 .BR semctl (2), .BR semget (2), .BR sigaction (2), .BR capabilities (7), .BR sem_overview (7), .BR svipc (7), .BR time (7)