From owner-freebsd-current@FreeBSD.ORG Tue Apr 19 16:53:56 2011 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 35546106566C; Tue, 19 Apr 2011 16:53:56 +0000 (UTC) (envelope-from rysto32@gmail.com) Received: from mail-ew0-f54.google.com (mail-ew0-f54.google.com [209.85.215.54]) by mx1.freebsd.org (Postfix) with ESMTP id 6F7748FC14; Tue, 19 Apr 2011 16:53:55 +0000 (UTC) Received: by ewy1 with SMTP id 1so2210701ewy.13 for ; Tue, 19 Apr 2011 09:53:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:date:message-id:subject:from:to:cc :content-type; bh=blpFMu7XZaAXA0fDHA7MTDmPrPuMXoBJWkPMjkh5DtA=; b=Wnvd00QLj9YaS1rHnxCL+VAttndMFIuEpLcALSNDO1ShbTlc2QD+goG2xv70jnOw4E Xyikdm2s/LGPe0gdMkyxb3cIDTj5I4eu/M8QwNVJ/ubHiFjoCGow6879Apr8ZKYpFr+f MWKjsB102uuncq+/TYVWLiZTwQOl27SQtlceA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:cc:content-type; b=Tdl405cNWflHX+lyf7atqz0MIOM2ZOxgyFvyDx44vk+D3VOmFDrH5Qaw2d/f9l7c6F ad0VpdZ4pxR8wDMCApVSg47YYo0IfIvWkgF6A/CObV0FT3kv9PRWRW3x+cq0habXN97o Wbtttyu7/YtZpnkhniM4rx1F0jisbjRzonKsE= MIME-Version: 1.0 Received: by 10.213.113.205 with SMTP id b13mr4517030ebq.62.1303232034253; Tue, 19 Apr 2011 09:53:54 -0700 (PDT) Received: by 10.213.32.4 with HTTP; Tue, 19 Apr 2011 09:53:54 -0700 (PDT) Date: Tue, 19 Apr 2011 12:53:54 -0400 Message-ID: From: Ryan Stone To: FreeBSD Current Content-Type: text/plain; charset=ISO-8859-1 Cc: Ed Maste , davidxu@freebsd.org Subject: [PATCH] Call _thr_check_init() from _pthread_once X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Apr 2011 16:53:56 -0000 In r179417 the implementation of pthread_once in libthr was changed from using a global pthread_mutex_t for synchronization to rolling its own synchronization mechanism. Unfortunately, this introduced a bug. Calling _pthread_mutex_lock implicitly ensured that _thr_check_init() had been called. In the current version, there is no such guarantee. This means that if your first call into libthr is pthread_once, your executable will segfault when it tries to access curthread. This patch resolves the issue for me: Index: lib/libthr/thread/thr_once.c =================================================================== --- lib/libthr/thread/thr_once.c (revision 220603) +++ lib/libthr/thread/thr_once.c (working copy) @@ -64,6 +64,8 @@ struct pthread *curthread; int state; + _thr_check_init(); + for (;;) { state = once_control->state; if (state == ONCE_DONE) If there are no objections I'll commit this soon.