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