home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / unix / programm / 3897 < prev    next >
Encoding:
Text File  |  1992-07-25  |  2.1 KB  |  51 lines

  1. Newsgroups: comp.unix.programmer
  2. Path: sparky!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!att!cbnewsk!ksc
  3. From: ksc@cbnewsk.cb.att.com (kenneth.s.cobler)
  4. Subject: Re: Shared Memory and Semaphores
  5. Organization: AT&T
  6. Distribution: usa
  7. Date: Fri, 24 Jul 1992 20:28:41 GMT
  8. Message-ID: <1992Jul24.202841.24341@cbnewsk.cb.att.com>
  9. References: <1992Jul23.155158.8075@gvl.unisys.com>
  10. Lines: 39
  11.  
  12. In article <1992Jul23.155158.8075@gvl.unisys.com> rickt@gvls1.gvl.unisys.com (Rick Thompson) writes:
  13. >
  14. >Hello,
  15. >
  16. >  I have a couple questions regaurding shared memory and semaphores.
  17. >
  18. >  1)  I've created a shared memory area using shmget and my processes
  19. >      can communicate correctly.  However, it is possible for any one of
  20. >      the processes to remove the partion even though the others are still
  21. >      using it.  The processes are all running under the same user so any
  22. >      process has permission to remove it.  Is there a way to prevent the
  23. >      removal if the memory is still in use?
  24.  
  25.     When a process requests IPC_RMID, the actual shared memory is not
  26.     released until no other process is attached to it.  So, you
  27.     are not in jeopardy of deleting an in-use shared memory segment.
  28.     However, if you do request a segment to be removed, no new
  29.     process can attach itself to the old shared memory.
  30. >
  31. >  2)  I need the ability to lock out a portion of shared memory in
  32. >      some critical regions of the code.  Is it possible using semget and
  33. >      semctl to do this?  Again, the processes using the shared memory are
  34. >      running under the same user.
  35. >
  36.     You could use a semaphore.  The critical code section
  37.     waits for the semaphore to be released, 
  38.     sets the semaphore, performs its operation, and then
  39.     releases the semaphore.  Use the lock semaphore
  40.     technique for all access to shared memory.  This will
  41.     ensure only one process performs its function upon shared
  42.     memory at a time.
  43.     
  44.     Note: watch out for race conditions.
  45.     
  46.     
  47. Kenneth Cobler        ksc@cbnewsk.att.com or ken@ihlpm.att.com
  48. AT&T Bell Laboratories    attmail!cbnewsk!ksc or attmail!ihlpm!ken
  49. 2000 N. Naperville Rd.
  50. Naperville, IL  60566
  51.