$NetBSD: patch-al,v 1.1 2007/09/25 04:18:27 bjs Exp $

Fixup locking order.  From OpenBSD.

--- pr/src/misc/prinit.c.orig	2006-11-30 19:34:11.000000000 -0500
+++ pr/src/misc/prinit.c
@@ -435,6 +435,12 @@ PR_IMPLEMENT(PRStatus) PR_Cleanup()
 	    _PR_LogCleanup();
 
         /*
+         * accesses the current thread
+         */
+        _PR_CleanupNet();
+        _PR_CleanupIO();
+
+        /*
          * This part should look like the end of _PR_NativeRunThread
          * and _PR_UserRunThread.
          */
@@ -446,6 +452,7 @@ PR_IMPLEMENT(PRStatus) PR_Cleanup()
             PR_DELETE(me->stack);
             PR_DELETE(me);
         }
+        _PR_MD_SET_CURRENT_THREAD(NULL);
 
         /*
          * XXX: We are freeing the heap memory here so that Purify won't
@@ -454,8 +461,6 @@ PR_IMPLEMENT(PRStatus) PR_Cleanup()
          * Ideally, for each _PR_InitXXX(), there should be a corresponding
          * _PR_XXXCleanup() that we can call here.
          */
-        _PR_CleanupNet();
-        _PR_CleanupIO();
 #ifdef WINNT
         _PR_CleanupCPUs();
 #endif
