In _PR_InitThreads, call pthread_init to explicitly initialize the
authorwtc%netscape.com
Mon, 01 Feb 1999 20:01:36 +0000
changeset 418 a7b5550bdb4b3f3844c9060c11b5d212dc2a5b4b
parent 417 857766699ffe11ca2c43853af912010c21607e27
child 419 10aea065cbad04e265101312d82a2b6d687e00be
push idunknown
push userunknown
push dateunknown
In _PR_InitThreads, call pthread_init to explicitly initialize the pthread subsystem on BSD/OS because pthread_self() fails to initialize pthreads implicitly. This patch is contributed by Bert Driehuis <bert_driehuis@nl.compuware.com>.
config/BSD_OS.mk
pr/src/pthreads/ptthread.c
--- a/config/BSD_OS.mk
+++ b/config/BSD_OS.mk
@@ -27,16 +27,17 @@ CCC		= g++
 else
 CC		= shlicc2
 CCC		= shlicc2
 endif
 RANLIB		= ranlib
 
 ifeq ($(USE_PTHREADS),1)
 IMPL_STRATEGY = _PTH
+DEFINES		+= -D_PR_NEED_PTHREAD_INIT
 else
 IMPL_STRATEGY = _EMU
 DEFINES		+= -D_PR_LOCAL_THREADS_ONLY
 endif
 
 OS_CFLAGS	= -DBSDI -DHAVE_STRERROR -D__386BSD__ -DNEED_BSDREGEX -Di386
 
 ifeq ($(OS_RELEASE),2.1)
--- a/pr/src/pthreads/ptthread.c
+++ b/pr/src/pthreads/ptthread.c
@@ -740,16 +740,27 @@ static void _pt_thread_death(void *arg)
 }  /* _pt_thread_death */
 
 void _PR_InitThreads(
     PRThreadType type, PRThreadPriority priority, PRUintn maxPTDs)
 {
     int rv;
     PRThread *thred;
 
+#ifdef _PR_NEED_PTHREAD_INIT
+    /*
+     * On BSD/OS (3.1 and 4.0), the pthread subsystem is lazily
+     * initialized, but pthread_self() fails to initialize
+     * pthreads and hence returns a null thread ID if invoked
+     * by the primordial thread before any other pthread call.
+     * So we explicitly initialize pthreads here.
+     */
+    pthread_init();
+#endif
+
 #if defined(_PR_DCETHREADS) || defined(_POSIX_THREAD_PRIORITY_SCHEDULING)
     /*
     ** These might be function evaluations
     */
     pt_book.minPrio = PT_PRIO_MIN;
     pt_book.maxPrio = PT_PRIO_MAX;
 #endif