Subject: CVS commit: src/lib/libpthread
To: None <>
From: Chuck Silvers <>
List: source-changes
Date: 10/19/2005 02:15:03
Module Name:	src
Committed By:	chs
Date:		Wed Oct 19 02:15:03 UTC 2005

Modified Files:
	src/lib/libpthread: pthread.c pthread_int.h pthread_mutex.c
	    pthread_rwlock.c sem.c

Log Message:
starting the pthread library (ie. calling pthread__start()) before
any threads are created turned out to be not such a good idea.
there are stronger requirements on what has to work in a forked child
while a process is still single-threaded.  so take all that stuff
back out and fix the problems with single-threaded programs that
are linked with libpthread differently, by checking if the library
has been started and doing completely different stuff if it hasn't been:
 - for pthread_rwlock_timedrdlock(), just fail with EDEADLK immediately.
 - for sem_wait(), the only thing that can unlock the semaphore is a
   signal handler, so use sigsuspend() to wait for a signal.
 - for pthread_mutex_lock_slow(), just go into an infinite loop
   waiting for signals.

I also noticed that there's a "sem2" test that has never worked in its
single-threaded form.  the problem there is that a signal handler tries
to take a sem_t interlock which is already held when the signal is received.
fix this too, by adding a single-threaded case for sig_trywait() that
blocks signals instead of using the userland interlock.

To generate a diff of this commit:
cvs rdiff -r1.44 -r1.45 src/lib/libpthread/pthread.c
cvs rdiff -r1.32 -r1.33 src/lib/libpthread/pthread_int.h
cvs rdiff -r1.20 -r1.21 src/lib/libpthread/pthread_mutex.c
cvs rdiff -r1.12 -r1.13 src/lib/libpthread/pthread_rwlock.c
cvs rdiff -r1.8 -r1.9 src/lib/libpthread/sem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.