Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 11 Aug 2000 19:30:47 -0700 (PDT)
From:      John Polstra <jdp@polstra.com>
To:        hackers@freebsd.org
Cc:        jonas.bulow@servicefactory.se
Subject:   Re: IPC, shared memory, syncronization
Message-ID:  <200008120230.TAA60410@vashon.polstra.com>
In-Reply-To: <39948331.5E83DE1B@servicefactory.se>
References:  <39943C37.76D2DBCC@servicefactory.se> <39948331.5E83DE1B@servicefactory.se>

next in thread | previous in thread | raw e-mail | index | archive | help
In article <39948331.5E83DE1B@servicefactory.se>,
Jonas Bulow  <jonas.bulow@servicefactory.se> wrote:
> Jonas Bulow wrote:
> > 
> > What is the "BSD-way" of access to shared memory (mmap:ed) secure (avoid
> > race conditions, etc)? Right now I'm using posix semaphores but I would
> > like to know if there is a substitute like the way kqueue is for
> > select/poll.
> 
> Hmm, I think I lost some word and deeper thought in my previous mail.
> :-)
> 
> The problem is as follows:
> 
> I have a couple of processes using a mmap:ed file as common data area.
> What I want to do is to make it safe for all processes to update data in
> this common memory area. I was thinking about using some part of the
> common data area for semaphores in some way. I just want a simple
> "test-and-set" operation I can use to make sure there is only one
> process writing to the common data area.

If you want the "BSD way" you should probably create a 0-length
temporary file somewhere and use the flock(2) system call on it.  The
file itself isn't important; it's just something to lock.

Or you could use semop(2) on semaphores.  But that's the SYSV way, not
the BSD way.

John
-- 
  John Polstra                                               jdp@polstra.com
  John D. Polstra & Co., Inc.                        Seattle, Washington USA
  "Disappointment is a good sign of basic intelligence."  -- Chögyam Trungpa



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200008120230.TAA60410>