From dd9b25a6caa24be4f3512ee2b4412e08333a476b Mon Sep 17 00:00:00 2001 From: Michael Kerrisk Date: Sat, 30 Jun 2007 13:14:42 +0000 Subject: [PATCH] Added an EXAMPLE code segment. --- man2/semop.2 | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/man2/semop.2 b/man2/semop.2 index 98ce1d52d..557256f00 100644 --- a/man2/semop.2 +++ b/man2/semop.2 @@ -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),