From owner-freebsd-hackers Fri Aug 11 19:31: 1 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from wall.polstra.com (rtrwan160.accessone.com [206.213.115.74]) by hub.freebsd.org (Postfix) with ESMTP id 30C0337B666 for ; Fri, 11 Aug 2000 19:30:58 -0700 (PDT) (envelope-from jdp@polstra.com) Received: from vashon.polstra.com (vashon.polstra.com [206.213.73.13]) by wall.polstra.com (8.9.3/8.9.3) with ESMTP id TAA27044; Fri, 11 Aug 2000 19:30:48 -0700 (PDT) (envelope-from jdp@polstra.com) From: John Polstra Received: (from jdp@localhost) by vashon.polstra.com (8.9.3/8.9.1) id TAA60410; Fri, 11 Aug 2000 19:30:47 -0700 (PDT) (envelope-from jdp@polstra.com) Date: Fri, 11 Aug 2000 19:30:47 -0700 (PDT) Message-Id: <200008120230.TAA60410@vashon.polstra.com> To: hackers@freebsd.org Reply-To: hackers@freebsd.org Cc: jonas.bulow@servicefactory.se Subject: Re: IPC, shared memory, syncronization In-Reply-To: <39948331.5E83DE1B@servicefactory.se> References: <39943C37.76D2DBCC@servicefactory.se> <39948331.5E83DE1B@servicefactory.se> Organization: Polstra & Co., Seattle, WA Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG In article <39948331.5E83DE1B@servicefactory.se>, Jonas Bulow 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