home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / unix / aix / 13821 < prev    next >
Encoding:
Internet Message Format  |  1993-01-28  |  1.6 KB

  1. Path: sparky!uunet!vnet.ibm.com
  2. From: pgainer@vnet.ibm.com (Patrick Gainer)
  3. Message-ID: <19930128.174358.873@almaden.ibm.com>
  4. Date: Thu, 28 Jan 93 19:13:15 EST
  5. Newsgroups: comp.unix.aix
  6. Subject: Re: semop overflows after 16,384 calls!
  7. Organization: IBM - Toronto Lab
  8. Disclaimer: This posting represents the poster's views, not those of IBM
  9. News-Software: UReply 3.0
  10. References: <01050810.oljql1@mbeckman.mbeckman.com>
  11. Lines: 50
  12.  
  13. In <01050810.oljql1@mbeckman.mbeckman.com> Mel Beckman writes:
  14. >We're using the semop operation to synchronize two tasks, where process A does
  15. >a semsignal, and process B does a semwait. The semop operation uses a semundo
  16. >flag so that the value of the semop is subtracted from the calling processes
  17. >
  18.  
  19. My advice would be to not use the semundo flag.
  20. Try something simpler like:
  21.  
  22. /*
  23.  * Routine to init sem to 1
  24.  */
  25. void init_sem(int *semid)
  26. {
  27.   *semid = semget(IPC_PRIVATE,1,IPC_CREAT|IPC_R|IPC_W);
  28.  
  29.   semctl(*semid, 0, SETVAL, 1);
  30. }
  31.  
  32. /*
  33.  * Routine to decrement semaphore. If 0 is decremented, process blocks.
  34.  */
  35. int
  36.   dec_sem(int    semid)
  37. {
  38.   static struct sembuf sembuf = {0,-1,0};
  39.  
  40.   return(semop(semid,&sembuf,1));
  41. }
  42.  
  43. /*
  44.  * Routine to increment semaphore. If 0 is incremented, previously blocked
  45.  * processes are awakened.
  46.  */
  47. int
  48.   sqlo_put_token(int    semid)
  49. {
  50.   static struct sembuf sembuf = {0,1,0};
  51.  
  52.   return(semop(semid,&sembuf,1));
  53. }
  54.  
  55. That should do the trick for synchronization.
  56.  
  57. >_____________________________________________________________________
  58. >| Mel beckman                  |    Internet: mbeckman@mbeckman.com |
  59.  
  60. Pat Gainer
  61. pgainer@vnet.ibm.com
  62.  
  63.