Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 7 Dec 1998 09:10:34 -0500 (EST)
From:      HighWind Software Information <info@highwind.com>
To:        current@FreeBSD.ORG
Subject:   Re: Thread fd locking and fork()
Message-ID:  <199812071410.JAA17159@highwind.com>

next in thread | raw e-mail | index | archive | help
Terry,

First, since this is POSIX thread fork() semantics, you don't
get a copy of all threads when you fork(). You just get the thread
that called fork(). At least, that is the way it should work and
appears to work.

Second, I don't see why it is bad for a threaded program to call
fork().  Why not? What if you need to exec() sendmail or some other
helper program?

Third, I still don't see why my patch is bad. After fork(), you have
one thread left. It makes no sense for the remaining fd's that are
open to be locked by threads that do not exist!

If they are simply unlocked/cleaned up in the child, the child is then
free to close() or manipulate those fd's.

This is the way it works on every other O/S. You can always: fork(),
then in the child, loop over fd's to close() the one's you want to
close(), then exec() a program.

-Rob

--

Insert in uthread_fork.c at line 122:

                        /*
                         * 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;
 
                                /* Initialise the read/write queues: */
                                _thread_queue_init(&_thread_fd_table[i]->r_queu\
e);
                                _thread_queue_init(&_thread_fd_table[i]->w_queu\
e);
                            }
                        }

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?199812071410.JAA17159>