From owner-freebsd-stable Fri Sep 29 4:21: 2 2000 Delivered-To: freebsd-stable@freebsd.org Received: from pcnet1.pcnet.com (pcnet1.pcnet.com [204.213.232.3]) by hub.freebsd.org (Postfix) with ESMTP id AF9C237B423 for ; Fri, 29 Sep 2000 04:20:14 -0700 (PDT) Received: (from eischen@localhost) by pcnet1.pcnet.com (8.8.7/PCNet) id HAA07194; Fri, 29 Sep 2000 07:19:55 -0400 (EDT) Date: Fri, 29 Sep 2000 07:19:54 -0400 (EDT) From: Daniel Eischen To: Roman Shterenzon Cc: freebsd-stable@FreeBSD.ORG Subject: Re: pthreads bug? In-Reply-To: <970215688.39d451088fbef@webmail.harmonic.co.il> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-stable@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Fri, 29 Sep 2000, Roman Shterenzon wrote: > Hello, > I noticed some strange behavior in pthreads applications, > close on socket which is in accept() will be blocked untill there's a connection > to port and accept returns. Correct. FreeBSD pthreads locks file descriptors while they're in use. Since the thread in accept() has the file descriptor locked, performing a close() on that same file descriptor in another thread will block until the accept completes. The same thing would happen if you were doing a read() on the socket with no data ready instead of the accept(). To fix your program (or openldap), ensure the signal gets directed to the thread in accept() and handle the EINTR, or have a signal handling thread that does sigwait() for SIGHUP (or whatever) and then kill the thread in accept() with pthread_kill(). You could also use pthread_cancel() if there is cleanup handling that the thread needs to do before exiting. FWIW, I'm not sure that our pthreads library should prevent programs from shooting themselves in the foot by locking file descriptors. I'm of the mind that people kill people, not guns ;-) But removing the automatic locking of file descriptors needs to be looked at closely to ensure that it doesn't cause problems for the threads library itself. I think POSIX also mandates locking for stdio fds. -- Dan Eischen To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-stable" in the body of the message