From owner-freebsd-hackers Fri Nov 21 15:00:44 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.7/8.8.7) id PAA22273 for hackers-outgoing; Fri, 21 Nov 1997 15:00:44 -0800 (PST) (envelope-from owner-freebsd-hackers) Received: from anlsun.ebr.anlw.anl.gov (anlsun.ebr.anlw.anl.gov [141.221.1.2]) by hub.freebsd.org (8.8.7/8.8.7) with SMTP id PAA22265 for ; Fri, 21 Nov 1997 15:00:39 -0800 (PST) (envelope-from cmott@srv.net) Received: from darkstar.home (tc-if2-34.ida.net [208.141.171.91]) by anlsun.ebr.anlw.anl.gov (8.6.11/8.6.11) with SMTP id PAA28906; Fri, 21 Nov 1997 15:58:08 -0700 Date: Fri, 21 Nov 1997 15:57:29 -0700 (MST) From: Charles Mott X-Sender: cmott@darkstar.home To: Curtis Bray cc: freebsd-hackers@freebsd.org Subject: Re: malloc() problems in children after using rfork() In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk On Fri, 21 Nov 1997, Curtis Bray wrote: > On Fri, 21 Nov 1997, Alex Nash wrote: > > On Fri, 21 Nov 1997, Curtis Bray wrote: > > > Hi, > > > > > > I'm trying to use rfork(RFPROC | RFMEM) so that all the children can > > > share the same address space with their parent. > > > > > > If I have multiple children issuing mallocs the children seem to core > > > dump. Once I turn the RFMEM flag off I have no problem mallocing (but > > > of course I loose the shared address space). Anyone know what I could > > > be doing wrong here? Do I have to put semaphores around every malloc?? > > > I hope that's not the case... Thanks in advance! > > > > The only locking malloc() performs is pthread_mutex_lock/unlock in the > > libc_r version. The non-threaded version provides no locking at all. > > > > I was hoping to avoid the pthread package because I need my threads (or > children processes in this case) to perform a lot of file IO. I appears > that since non-blocking file IO doesn't exist in 4.4BSD that this approach > would cause all my threads to block while one of them is waiting for data > off the disk. Obviously this defeats the purpose of a threaded app! > > From what I'd seen in the mail list archives, it appears the rfork() > method may work better for these IO bound applications. I was assuming > that once the RFMEM flag was set, then the VM system would respect > multiple children sharing the same address space. That's what I've > gotten from the man pages anyway: > > man 2 rfork: > > RFMEM If set, the kernel will force sharing of the entire ad- > dress space. The child will then inherit all the shared > segments the parent process owns. Other segment types > will be unaffected. Subsequent forks by the parent will > then propagate the shared data and bss between children. > The stack segment is always split. May be set only with > RFPROC. > > Am I mistaken in this approach? > > Curtis > I've been dealing a little with the same problem, and I decided to use regular forking and then to use mmap() to have a shared memory area between processes. I know threading is supposed to be great and all, but what I see is alot of minor dfferences between operating systems that make it difficult to be really portable. Often thread-safe libraries are missing on target systems or have slightly different function names (like Solaris). rfork() looks like an interesting function, but it doesn't seen widespread in Unix yet (I just checked for it on linux and OSF). I seem to remember Linus making a a big deal about a clone() call. Charles Mott