[Python-checkins] CVS: python/dist/src/Python thread_pthread.h,2.32,2.33

Guido van Rossum gvanrossum@users.sourceforge.net
Fri, 12 Oct 2001 14:49:19 -0700


Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv25724

Modified Files:
	thread_pthread.h 
Log Message:
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:

   This patch updates Python/thread_pthread.h to mask all 
   signals for any thread created. This will keep all 
   signals masked for any thread that isn't the initial 
   thread. For Solaris and Linux, the two platforms I was 
   able to test it on, it solves bug #465673 (pthreads 
   need signal protection) and probably will solve bug 
   #219772 (Interactive InterPreter+ Thread -> core dump 
   at exit). 

   I'd be great if this could get some testing on other 
   platforms, especially HP-UX pre 11.00 and post 11.00, 
   as I had to make some guesses for the DCE thread case. 
   AIX is also a concern as I saw some mention of using 
   sigthreadmask() as a pthread_sigmask() equivalent, but 
   this patch doesn't use sigthreadmask(). I don't have 
   access to AIX. 


Index: thread_pthread.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/thread_pthread.h,v
retrieving revision 2.32
retrieving revision 2.33
diff -C2 -d -r2.32 -r2.33
*** thread_pthread.h	2001/09/10 14:10:54	2.32
--- thread_pthread.h	2001/10/12 21:49:17	2.33
***************
*** 5,8 ****
--- 5,9 ----
  #include <string.h>
  #include <pthread.h>
+ #include <signal.h>
  
  
***************
*** 70,73 ****
--- 71,86 ----
  
  
+ /* On platforms that don't use standard POSIX threads pthread_sigmask()
+  * isn't present.  DEC threads uses sigprocmask() instead as do most
+  * other UNIX International compliant systems that don't have the full
+  * pthread implementation.
+  */
+ #ifdef PY_PTHREAD_STD
+ #  define SET_THREAD_SIGMASK pthread_sigmask
+ #else
+ #  define SET_THREAD_SIGMASK sigprocmask
+ #endif
+ 
+ 
  /* A pthread mutex isn't sufficient to model the Python lock type
   * because, according to Draft 5 of the docs (P1003.4a/D5), both of the
***************
*** 136,139 ****
--- 149,153 ----
  	pthread_t th;
  	int success;
+  	sigset_t oldmask, newmask;
  #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED)
  	pthread_attr_t attrs;
***************
*** 152,155 ****
--- 166,177 ----
          pthread_attr_setscope(&attrs, PTHREAD_SCOPE_SYSTEM);
  #endif
+ 
+ 	/* Mask all signals in the current thread before creating the new
+ 	 * thread.  This causes the new thread to start with all signals
+ 	 * blocked.
+ 	 */
+ 	sigfillset(&newmask);
+ 	SET_THREAD_SIGMASK(SIG_BLOCK, &newmask, &oldmask);
+ 
  	success = pthread_create(&th, 
  #if defined(PY_PTHREAD_D4)
***************
*** 175,178 ****
--- 197,204 ----
  #endif
  				 );
+ 
+ 	/* Restore signal mask for original thread */
+ 	SET_THREAD_SIGMASK(SIG_SETMASK, &oldmask, NULL);
+ 
  #ifdef THREAD_STACK_SIZE
  	pthread_attr_destroy(&attrs);