home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!vnet.ibm.com
- From: pgainer@vnet.ibm.com (Patrick Gainer)
- Message-ID: <19930128.174358.873@almaden.ibm.com>
- Date: Thu, 28 Jan 93 19:13:15 EST
- Newsgroups: comp.unix.aix
- Subject: Re: semop overflows after 16,384 calls!
- Organization: IBM - Toronto Lab
- Disclaimer: This posting represents the poster's views, not those of IBM
- News-Software: UReply 3.0
- References: <01050810.oljql1@mbeckman.mbeckman.com>
- Lines: 50
-
- In <01050810.oljql1@mbeckman.mbeckman.com> Mel Beckman writes:
- >We're using the semop operation to synchronize two tasks, where process A does
- >a semsignal, and process B does a semwait. The semop operation uses a semundo
- >flag so that the value of the semop is subtracted from the calling processes
- >
-
- My advice would be to not use the semundo flag.
- Try something simpler like:
-
- /*
- * Routine to init sem to 1
- */
- void init_sem(int *semid)
- {
- *semid = semget(IPC_PRIVATE,1,IPC_CREAT|IPC_R|IPC_W);
-
- semctl(*semid, 0, SETVAL, 1);
- }
-
- /*
- * Routine to decrement semaphore. If 0 is decremented, process blocks.
- */
- int
- dec_sem(int semid)
- {
- static struct sembuf sembuf = {0,-1,0};
-
- return(semop(semid,&sembuf,1));
- }
-
- /*
- * Routine to increment semaphore. If 0 is incremented, previously blocked
- * processes are awakened.
- */
- int
- sqlo_put_token(int semid)
- {
- static struct sembuf sembuf = {0,1,0};
-
- return(semop(semid,&sembuf,1));
- }
-
- That should do the trick for synchronization.
-
- >_____________________________________________________________________
- >| Mel beckman | Internet: mbeckman@mbeckman.com |
-
- Pat Gainer
- pgainer@vnet.ibm.com
-
-