From owner-freebsd-threads@FreeBSD.ORG Thu May 6 06:04:52 2004 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id CD2ED16A4CE for ; Thu, 6 May 2004 06:04:52 -0700 (PDT) Received: from telecom.net.et (sparrow.telecom.net.et [213.55.64.38]) by mx1.FreeBSD.org (Postfix) with ESMTP id F0B7543D39 for ; Thu, 6 May 2004 06:04:46 -0700 (PDT) (envelope-from mtm@identd.net) Received: from [213.55.69.234] (HELO pool-151-200-10-97.res.east.verizon.net) by telecom.net.et (CommuniGate Pro SMTP 3.4.8) with ESMTP-TLS id 44677347 for freebsd-threads@freebsd.org; Thu, 06 May 2004 15:59:45 +0300 Received: from rogue.acs-et.com (localhost [127.0.0.1]) ESMTP id i46D5afI005507 for ; Thu, 6 May 2004 16:05:37 +0300 (EAT) (envelope-from mtm@rogue.acs-et.com) Received: (from mtm@localhost) by rogue.acs-et.com (8.12.11/8.12.11/Submit) id i46D5Zj3005506 for freebsd-threads@freebsd.org; Thu, 6 May 2004 16:05:35 +0300 (EAT) (envelope-from mtm) Date: Thu, 6 May 2004 16:05:33 +0300 From: Mike Makonnen To: freebsd-threads@freebsd.org Message-ID: <20040506130533.GA4835@rogue.acs-et.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.1i X-Operating-System: FreeBSD/5.2-CURRENT (i386) Subject: large libthr patch X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 May 2004 13:04:53 -0000 Hello folks, I have a largish libthr patch ready for committing. You can get it at http://people.freebsd.org/~mtm/patches/async-sig-safe.diff I would appreciate reviews and tests (it passes all conformance/regression tests that the previous version passed-- and a few it failed). Draft commit-log: Make libthr async-signal-safe without costly signal masking. The guidlines I followed are: Only 3 functions (pthread_cancel, pthread_setcancelstate, pthread_setcanceltype) are required to be async-signal-safe. None, of the rest of the pthread api is required to be async-signal-safe. This means that none of the other pthread_* functions are safe to use from inside a signal handler. However, there are certain system/libc calls that are cancellation points that a caller may call from within a signal handler, and since they are cancellation points calls have to be made into libthr to test for cancellation and exit the thread if necessary. So, the cancellation test and thread exit code paths must be async-signal-safe as well. To achieve this I have had to alter the pthread structure. A summary of the changes follows: o Almost all of the code paths that masked signals, as well as locking the pthread structure now lock only the pthread structure. o Signals are masked (and left that way) as soon as a thread enters pthread_exit(). o The active and dead threads locks now explicitly require that signals are masked. o Access to the isdead field of the pthread structure is protected by both the active and dead list locks for writing. Either one is sufficient for reading. o The thread state and type fields have been combined into one three-state switch to make it easier to read without requiring a lock. It doesn't need a lock for writing (and therefore for reading either) because only the current thread can write to it and it is an integer value. o The thread state field of the pthread structure has been eliminated. It was an unnecessary field that mostly duplicated the flags field, but required additional locking that would make a lot more code paths require signal masking. Any truly unique values (such as PS_DEAD) have been reborn as separate members of the pthread structure. o Since the mutex and condvar pthread functions are not async-signal-safe there is no need to muck about with the wait queues when handling a signal ... o ... which also removes the need for wrapping signal handlers and sigaction(2). o The condvar and mutex async-cancellation code had to be revised as a result of some of these changes, which resulted in semi-unrelated changes which would have been difficult to work on as a separate commit, so they are included as well. The only part of the changes I am worried about is related to locking for 'pthread joining' related operations. But, I will take a closer look at them once this mega-patch is committed. Cheers. -- Mike Makonnen | GPG-KEY: http://www.identd.net/~mtm/mtm.asc mtm@identd.net | Fingerprint: AC7B 5672 2D11 F4D0 EBF8 5279 5359 2B82 7CD4 1F55 mtm@FreeBSD.Org| FreeBSD - Unleash the Daemon !