Date: Thu, 3 Dec 1998 20:56:35 -0500 (EST) From: HighWind Software Information <info@highwind.com> To: Kurt@OpenLDAP.Org Cc: current@FreeBSD.ORG Subject: Re: Thread fd locking and fork() Message-ID: <199812040156.UAA08468@highwind.com> In-Reply-To: <3.0.5.32.19981203124540.00b03b80@localhost> (Kurt@OpenLDAP.Org)
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199812040156.UAA08468>