From owner-freebsd-current@FreeBSD.ORG Mon Mar 9 20:55:50 2009 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 C3794106566B for ; Mon, 9 Mar 2009 20:55:50 +0000 (UTC) (envelope-from justin.teller@gmail.com) Received: from yx-out-2324.google.com (yx-out-2324.google.com [74.125.44.29]) by mx1.freebsd.org (Postfix) with ESMTP id 7C4448FC18 for ; Mon, 9 Mar 2009 20:55:50 +0000 (UTC) (envelope-from justin.teller@gmail.com) Received: by yx-out-2324.google.com with SMTP id 31so837016yxl.13 for ; Mon, 09 Mar 2009 13:55:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=HRCqCS2Xb1p9zf6V89rnU3Ytg9XSffnJ9oGHYxHX+AY=; b=sJG9giNEsEllveqw3BlWst9LSN0+80SPbhXinxe9lg/AWTPM3BBt8idjz6jLNjCaZ4 mynLUgQIM37fIBjCKy8FHWzrQL3e0PPMUkR+z3E/FtWGRWhOX2PjPUcWUNPKtTrGvWd4 0gHJKoil0FQv6S4sFYpRbxweSXekddXin0m+I= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=wUlPe1SrypPHqKoVNdWW3oVe6rnyiZc6zr4Wyc5+FDC6xGzdd/mc/r7scQwXfaNHrX 8kHbR5mciDXKPHdMmBtAjVJymrYEJojxvr4Iqn9hMut/nIbKNuLxTbdBCavYtErzaa4e A89rbwEKcI6rNeC1lDVc6o2nmNsf7Xy2f+MkA= MIME-Version: 1.0 Received: by 10.142.217.17 with SMTP id p17mr2701252wfg.235.1236632149412; Mon, 09 Mar 2009 13:55:49 -0700 (PDT) In-Reply-To: <3561C827-66BD-4B3F-A3D4-97C4C06884B4@gmail.com> References: <3561C827-66BD-4B3F-A3D4-97C4C06884B4@gmail.com> Date: Mon, 9 Mar 2009 13:55:49 -0700 Message-ID: From: Justin Teller To: "freebsd-current@freebsd.org" Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: Re: Using PTHREAD_PRIO_INHERIT causes panic in kern_umtx.c 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: Mon, 09 Mar 2009 20:55:51 -0000 On Mon, Mar 9, 2009 at 12:02 PM, Justin Teller wrote: > When I compile and run the attached program, it panics my system, (FreeBSD > CURRENT as of 2-20-09) with the following message: > > panic: Assertion pi != NULL failed at /usr/src/sys/kern/kern_umtx: 1464 > > With the backtrace being: > Tracing pid 1079 tid 100045 td 0xffffff00037c8000 > kdb_enter() at kdb_enter+0x40 > panic() at panic+0x1ec > umtx_pi_adjust() at umtx_pi_adjust+0xfc8 > umtx_pi_adjust() at umtx_pi_adjust+0x19bd > _umtx_unlock() at _umtx_unlock+0x2c41 > _umtx_op() at _umtx_op+0x22 > syscall() at syscall+0x1f4 > Xfast_syscall() at Xfast_syscall+0xaa > --- syscall (454, FreeBSD ELF64, _umtx_op), rip = 0x4056ac, rsp = > 0x7fffffbfef38, rbp = 0x80060b150 --- > > This problem only shows up when I use PTHREAD_PRIO_INHERIT -- if I change > the line for pthread_mutexattr_setprotocol to PTHREAD_PRIO_NONE, then it > works fine. I've been trying to trace thru the code to figure out where > uq_pi_blocked should be setup, but I'm not too familiar with the code so I > haven't found where the problem originates. How can I get > PTHREAD_PRIO_INHERIT to work? And even if the change is in user-space, it > probably shouldn't be this easy to panic the kernel :-) > > -Justin > > > PS I'm reasonably certain that the most recent checkins (between now and > Feb 20th) wouldn't fix this, but if I'm wrong, just let me know! > > > > It looks like the list stripped out the .cpp file ... here it is below. To compile, run c++ -lthr mutex_prio_example.cpp -o mutex_prio_example mutex_prio_example: #include #include #define NRUNS 1000000 #define NCONSUMERS 4 volatile int g_num_items; pthread_mutex_t g_mutex; void* producer_proc ( void* ) { for ( int i = 0; i < NRUNS * NCONSUMERS; ++i ) { pthread_mutex_lock( &g_mutex ); ++g_num_items; pthread_mutex_unlock( &g_mutex ); } return NULL; } void* consumer_proc ( void* ) { for ( int i = 0; i < NRUNS; ++i ) { pthread_mutex_lock( &g_mutex ); --g_num_items; pthread_mutex_unlock( &g_mutex ); } return NULL; } int main() { g_num_items = 0; pthread_mutexattr_t mattr; pthread_mutexattr_init( &mattr ); pthread_mutexattr_setprotocol( &mattr, PTHREAD_PRIO_INHERIT ); pthread_mutex_init( &g_mutex, &mattr ); pthread_mutexattr_destroy( &mattr ); const int num_workers = NCONSUMERS; pthread_t threads[num_workers]; for ( int i = 0; i < num_workers; ++i ) pthread_create( threads + i, NULL, consumer_proc, NULL); producer_proc(NULL); for ( int i = 0; i < num_workers; ++i ) pthread_join( threads[i], NULL ); printf("done\n"); return 0; }