Subject: kern/33287: lwp assertion panic
To: None <kern-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: None <g.mcgarry@ieee.org>
List: netbsd-bugs
Date: 04/18/2006 20:10:00
>Number:         33287
>Category:       kern
>Synopsis:       lwp assertion panic
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Apr 18 20:10:00 +0000 2006
>Originator:     Gregory McGarry
>Release:        NetBSD-current
>Organization:
>Environment:
NetBSD/i386, single-CPU machine.
>Description:
While writing a custom pthread library which doesn't use scheduler activations, I obtained the following kernel panic:

panic:kernel diagnostic assertion "p->p_nrlwps == 1" failed: file "/usr/src/sys/kern/kern_exit.c", line 449

The process actually has two LWPs, the main LWP and another created with _lwp_create().  The first LWP acquires a mutex.  The second LWP suspends itself using _lwp_suspend() while waiting for this mutex.  When the first LWP releases the mutex, it invokes _lwp_continue() on the second LWP.  This second LWP immediately asserts to stop the process and view the debugging information.  It's during the process exit that the kernel panic occurs.

It looks like a race condition of a sort.  It's not 100% reproducible, which also indicates a race condition.
>How-To-Repeat:

>Fix: