Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cornell!uw-beaver!rice!sun-spots-request From: mustajar@rc.nokia.fi (Jari Mustaj{rvi RC 940) Newsgroups: comp.sys.sun Subject: SparcStation semaphores Message-ID: <6157@brazos.Rice.edu> Date: 28 Mar 90 09:50:39 GMT Sender: root@rice.edu Organization: Sun-Spots Lines: 73 Keywords: Miscellaneous Approved: Sun-Spots@rice.edu X-Sun-Spots-Digest: Volume 9, Issue 99, message 8 I have this mysterious problem, that I can't solve myself. I hope someone could help me.. At the end of this follows a little test, which doesn't pass in SPARC Stations, but works very well in SUN 3 machines. Both environments use System 5 libraries. The problem is the semaphore call semctl with third argument IPC_STAT. Otherwise the semaphores work very well. I have compiled the test using following script ( assuming the source file is called rossi.c ) /usr/5bin/cc -o rossi rossi.c Test command is 'rossi 100' Output from SPARC:: using argument semaphore key number 100 semctl: Bad address semctl: semid = 210, pars.sem_nsems = 33027 Output from SUN 3/50:: using argument semaphore key number 100 semctl: semid = 110, pars.sem_nsems = 1 And next the test: #include #include #include #include #include #include #define SEMKEY 95 main (argc, argv) int argc; char *argv[]; { int semid ; int semkey ; struct sembuf sop; struct semid_ds pars ; if (argc == 2) { semkey = atoi (argv [1]) ; printf ("using argument semaphore key number %d\n", semkey) ; } else { semkey = SEMKEY ; printf ("using default semaphore key number %d\n", semkey) ; } semid = semget ( SEMKEY,1,(IPC_CREAT|IPC_EXCL|0600)); if(semid == -1) perror("semget"); sop.sem_flg = 0; sop.sem_num = 0; sop.sem_op = 1; if (semop(semid,&sop,1) == -1) perror("semop"); if (semctl(semid,0,IPC_STAT,&pars) == -1) perror("semctl") ; printf("semctl: semid = %d, pars.sem_nsems = %d\n",semid,pars.sem_nsems) ; if (semctl(semid,0,IPC_RMID,0)) perror("semctl"); } Regards, Jari Mustajarvi.