From owner-freebsd-current Thu Dec 3 17:57:33 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id RAA03009 for freebsd-current-outgoing; Thu, 3 Dec 1998 17:57:33 -0800 (PST) (envelope-from owner-freebsd-current@FreeBSD.ORG) Received: from highwind.com (hurricane.highwind.com [209.61.45.50]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id RAA03002 for ; Thu, 3 Dec 1998 17:57:29 -0800 (PST) (envelope-from info@highwind.com) Received: (from info@localhost) by highwind.com (8.8.6/8.8.6) id UAA08468; Thu, 3 Dec 1998 20:56:35 -0500 (EST) Date: Thu, 3 Dec 1998 20:56:35 -0500 (EST) Message-Id: <199812040156.UAA08468@highwind.com> From: HighWind Software Information To: Kurt@OpenLDAP.Org CC: current@FreeBSD.ORG In-reply-to: <3.0.5.32.19981203124540.00b03b80@localhost> (Kurt@OpenLDAP.Org) Subject: Re: Thread fd locking and fork() Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG In a Posix Threads environment, state of locks should not be changed. If it's locked in the parent it must be locked in the child. Posix Threads provides the pthread_atfork() function to allow the parent to specify routines to manage fork()'ing... however it's not implemented in FreeBSD. If it was, you could argue that -lc_r probably should push an atfork cleanup handler. Kurt, 1. I agree with you 100%. However, these locks are simply libc_r internals and have nothing to do with locks the application can see. 2. libc_r simply doesn't do the right thing with regard to these internal fd locks in the case of fork(). 3. My patch causes absolutely no harm and fixes the problem. An atfork() handler will not work since it can't get inside the libc_r library and no external calls exist to touch these hidden libc_r private locks. I've tested this and it works like a champ. If someone with commit priv's could take a look at this simple code fragment for libc_r's uthread_fork.c, I'd greatly appreciate it. It needs to be inserted after fork() does its "kill all the threads but this one" thing. /* * Enter a loop to remove all locks on all locked fd's */ for (i = 0; i < _thread_dtablesize; i++) { if (_thread_fd_table[i] != NULL) { memset(&_thread_fd_table[i]->lock, 0, sizeof(_thread_fd_table[i]->lock)); _thread_fd_table[i]->r_owner = NULL; _thread_fd_table[i]->w_owner = NULL; _thread_fd_table[i]->r_fname = NULL; _thread_fd_table[i]->w_fname = NULL; _thread_fd_table[i]->r_lineno = 0;; _thread_fd_table[i]->w_lineno = 0;; _thread_fd_table[i]->r_lockcount = 0; _thread_fd_table[i]->w_lockcount = 0; /* Initialize the read/write queues: */ _thread_queue_init(&_thread_fd_table[i]->r_queu\ e); _thread_queue_init(&_thread_fd_table[i]->w_queu\ e); } } -Rob To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message