Manual may mislead many mighty men.

Ravi Ramachandran rr at csuna.cs.uh.edu
Sat Mar 17 23:21:12 AEST 1990


First, apologies if this subject has been thrashed to death before.
Now, let the mystery story unfold.


I remember that when I first tried fooling around with semaphores, I
had a little trouble. Then I pulled out the stuff from a nice book: 
"UNIX System V  Prog. Guide" (AT&T) - Prentice hall.

A pal of mine was trying to use semaphores on a Sys V Rel 3 system,
yesterday, and was having trouble with the semop() command.

To quote from the manual,
int semop(semid, sops, nsops)
int semid;
struct sembuf **sops;
int nsops;


while my program had,

struct sembuf sops[10];
   rtrn = semop(semid, sops, nsops);

Throw your concentration on the second field. As you can see, they are
different. (Modified his program & it worked.)  However, we couldn't
believe that the manual could be wrong. Decided to refer to the books
by the gurus.


Looked up "Adv. Unix Prog." (Marc J. Rochkind) - Prentice Hall.

On pg 188, he says (prob. from the manual):
int semop(sid, ops, nops)
int sid;
struct sembuf (*ops)[];
int nops;

However, the program on pg. 190  goes:
  struct sembuf sb;
  semop(semid, &sb, 1);


Finally, checked up "The Design of the UNIX operating system"  (Maurice
J. Bach)  - Prentice-Hall.
On pg. 373 he says, "...oplist is a pointer to an array of semaphore
operations ..." 
(It should be " oplist is an array of ..." ?)

The prog. in Fig 11.14 gives:
struct sembuf  psembuf, vsembuf;
semop(semid, &psembuf, 1);
semop(semid, &vsembuf, 1);


As a last measure, ran my version of semaphores on a Tolerant, Pyramid,
and an OST. Works. Checked the man pages on all these systems. They
are the ones with the double pointer. So, what's the deal? I know there
must be zillions of people who have noticed this before.


The butler did it,
  --ravi-


PS: Just check the SUN man pages; seems to be the right way: 
int semop(semid, sops, nsops)
int semid;
struct sembuf *sops;
int nsops;

PPS: The only reason that I've mentioned a couple of books here is b'cos
those books have been my UNIX bibles.



More information about the Comp.unix.wizards mailing list