Added an EXAMPLE code segment.

This commit is contained in:
Michael Kerrisk 2007-06-30 13:14:42 +00:00
parent 6a2df4ee5e
commit dd9b25a6ca
1 changed files with 27 additions and 1 deletions

View File

@ -28,8 +28,9 @@
.\" 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.
.\"
.TH SEMOP 2 2004-11-10 "Linux" "Linux Programmer's Manual"
.TH SEMOP 2 2007-07-09 "Linux" "Linux Programmer's Manual"
.SH NAME
semop, semtimedop \- semaphore operations
.SH SYNOPSIS
@ -478,6 +479,31 @@ This bug is fixed in kernel 2.6.11.
.\" http://marc.theaimsgroup.com/?l=linux-kernel&m=110260821123863&w=2
.\" the fix:
.\" http://marc.theaimsgroup.com/?l=linux-kernel&m=110261701025794&w=2
.SH EXAMPLE
The following code segment uses
.BR semop ()
to atomically wait for the value of semaphore 0 to become zero,
and then increment the semaphore value by one.
.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 = 0; /* Increment value by one */
sops[1].sem_flg = 0;
if (semop(semid, &sop, 2) == \-1) {
perror("semop");
exit(EXIT_FAILURE);
}
.fi
.SH "SEE ALSO"
.BR semctl (2),
.BR semget (2),