[Python-checkins] CVS: python/dist/src/Python thread.c,2.38,2.39 thread_beos.h,2.6,2.7 thread_cthread.h,2.14,2.15 thread_foobar.h,2.11,2.12 thread_lwp.h,2.14,2.15 thread_nt.h,2.18,2.19 thread_os2.h,2.10,2.11 thread_pth.h,2.7,2.8 thread_pthread.h,2.34,2.35 thread_sgi.h,2.14,2.15 thread_solaris.h,2.15,2.16 thread_wince.h,2.6,2.7

Guido van Rossum gvanrossum@users.sourceforge.net
Tue, 16 Oct 2001 14:13:51 -0700


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

Modified Files:
	thread.c thread_beos.h thread_cthread.h thread_foobar.h 
	thread_lwp.h thread_nt.h thread_os2.h thread_pth.h 
	thread_pthread.h thread_sgi.h thread_solaris.h thread_wince.h 
Log Message:
Partial patch from SF #452266, by Jason Petrone.

This changes Pythread_start_thread() to return the thread ID, or -1
for an error.  (It's technically an incompatible API change, but I
doubt anyone calls it.)



Index: thread.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/thread.c,v
retrieving revision 2.38
retrieving revision 2.39
diff -C2 -d -r2.38 -r2.39
*** thread.c	2001/07/26 21:34:59	2.38
--- thread.c	2001/10/16 21:13:49	2.39
***************
*** 112,116 ****
  #ifdef HAVE_PTH
  #include "thread_pth.h"
- #undef _POSIX_THREADS
  #endif
  
--- 112,115 ----

Index: thread_beos.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/thread_beos.h,v
retrieving revision 2.6
retrieving revision 2.7
diff -C2 -d -r2.6 -r2.7
*** thread_beos.h	2000/09/01 23:29:28	2.6
--- thread_beos.h	2001/10/16 21:13:49	2.7
***************
*** 113,117 ****
  static int32 thread_count = 0;
  
! int PyThread_start_new_thread( void (*func)(void *), void *arg )
  {
  	status_t success = 0;
--- 113,117 ----
  static int32 thread_count = 0;
  
! long PyThread_start_new_thread( void (*func)(void *), void *arg )
  {
  	status_t success = 0;
***************
*** 132,136 ****
  	}
  
! 	return ( success == B_NO_ERROR ? 1 : 0 );
  }
  
--- 132,136 ----
  	}
  
! 	return ( success == B_NO_ERROR ? tid : -1 );
  }
  

Index: thread_cthread.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/thread_cthread.h,v
retrieving revision 2.14
retrieving revision 2.15
diff -C2 -d -r2.14 -r2.15
*** thread_cthread.h	2000/11/13 19:45:45	2.14
--- thread_cthread.h	2001/10/16 21:13:49	2.15
***************
*** 15,19 ****
   * Thread support.
   */
! int
  PyThread_start_new_thread(void (*func)(void *), void *arg)
  {
--- 15,19 ----
   * Thread support.
   */
! long
  PyThread_start_new_thread(void (*func)(void *), void *arg)
  {
***************
*** 28,32 ****
  	 */
  	cthread_detach(cthread_fork((cthread_fn_t) func, arg));
! 	return success < 0 ? 0 : 1;
  }
  
--- 28,32 ----
  	 */
  	cthread_detach(cthread_fork((cthread_fn_t) func, arg));
! 	return success < 0 ? -1 : 0;
  }
  

Index: thread_foobar.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/thread_foobar.h,v
retrieving revision 2.11
retrieving revision 2.12
diff -C2 -d -r2.11 -r2.12
*** thread_foobar.h	2000/09/01 23:29:28	2.11
--- thread_foobar.h	2001/10/16 21:13:49	2.12
***************
*** 11,15 ****
   * Thread support.
   */
! int
  PyThread_start_new_thread(void (*func)(void *), void *arg)
  {
--- 11,15 ----
   * Thread support.
   */
! long
  PyThread_start_new_thread(void (*func)(void *), void *arg)
  {
***************
*** 20,24 ****
  	if (!initialized)
  		PyThread_init_thread();
! 	return success < 0 ? 0 : 1;
  }
  
--- 20,24 ----
  	if (!initialized)
  		PyThread_init_thread();
! 	return success < 0 ? -1 : 0;
  }
  

Index: thread_lwp.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/thread_lwp.h,v
retrieving revision 2.14
retrieving revision 2.15
diff -C2 -d -r2.14 -r2.15
*** thread_lwp.h	2000/09/01 23:29:28	2.14
--- thread_lwp.h	2001/10/16 21:13:49	2.15
***************
*** 27,31 ****
  
  
! int PyThread_start_new_thread(void (*func)(void *), void *arg)
  {
  	thread_t tid;
--- 27,31 ----
  
  
! long PyThread_start_new_thread(void (*func)(void *), void *arg)
  {
  	thread_t tid;
***************
*** 35,39 ****
  		PyThread_init_thread();
  	success = lwp_create(&tid, func, MINPRIO, 0, lwp_newstk(), 1, arg);
! 	return success < 0 ? 0 : 1;
  }
  
--- 35,39 ----
  		PyThread_init_thread();
  	success = lwp_create(&tid, func, MINPRIO, 0, lwp_newstk(), 1, arg);
! 	return success < 0 ? -1 : 0;
  }
  

Index: thread_nt.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/thread_nt.h,v
retrieving revision 2.18
retrieving revision 2.19
diff -C2 -d -r2.18 -r2.19
*** thread_nt.h	2001/08/29 21:37:10	2.18
--- thread_nt.h	2001/10/16 21:13:49	2.19
***************
*** 6,9 ****
--- 6,10 ----
  #include <limits.h>
  #include <process.h>
+ #include <Python.h>
  
  typedef struct NRMUTEX {
***************
*** 13,16 ****
--- 14,19 ----
  } NRMUTEX, *PNRMUTEX ;
  
+ /* dictionary to correlate thread ids with the handle needed to terminate them*/
+ static PyObject *threads = NULL;
  
  typedef PVOID WINAPI interlocked_cmp_xchg_t(PVOID *dest, PVOID exc, PVOID comperand) ;
***************
*** 146,149 ****
--- 149,153 ----
  static void PyThread__init_thread(void)
  {
+ 	threads = PyDict_New();
  }
  
***************
*** 151,158 ****
   * Thread support.
   */
! int PyThread_start_new_thread(void (*func)(void *), void *arg)
  {
  	unsigned long rv;
  	int success = 0;
  
  	dprintf(("%ld: PyThread_start_new_thread called\n", PyThread_get_thread_ident()));
--- 155,187 ----
   * Thread support.
   */
! 
! typedef struct {
! 	void (*func)(void*);
! 	void *arg;			
! 	long id;
! 	HANDLE done;
! } callobj;
! 
! static int
! bootstrap(void *call)
! {
! 	callobj *obj = (callobj*)call;
! 	/* copy callobj since other thread might free it before we're done */
! 	void (*func)(void*) = obj->func;
! 	void *arg = obj->arg;
! 
! 	obj->id = PyThread_get_thread_ident();
! 	ReleaseSemaphore(obj->done, 1, NULL);
! 	func(arg);
! 	return 0;
! }
! 
! long PyThread_start_new_thread(void (*func)(void *), void *arg)
  {
  	unsigned long rv;
  	int success = 0;
+ 	callobj *obj;
+ 	int id;
+ 	PyObject *key, *val;
  
  	dprintf(("%ld: PyThread_start_new_thread called\n", PyThread_get_thread_ident()));
***************
*** 160,164 ****
  		PyThread_init_thread();
  
! 	rv = _beginthread(func, 0, arg); /* use default stack size */
   
  	if (rv != (unsigned long)-1) {
--- 189,198 ----
  		PyThread_init_thread();
  
! 	obj = malloc(sizeof(callobj)); 
! 	obj->func = func;
! 	obj->arg = arg;
! 	obj->done = CreateSemaphore(NULL, 0, 1, NULL);
! 
! 	rv = _beginthread(func, 0, obj); /* use default stack size */
   
  	if (rv != (unsigned long)-1) {
***************
*** 167,171 ****
  	}
  
! 	return success;
  }
  
--- 201,213 ----
  	}
  
! 	/* wait for thread to initialize and retrieve id */
! 	WaitForSingleObject(obj->done, 5000);  /* maybe INFINITE instead of 5000? */
! 	CloseHandle((HANDLE)obj->done);
! 	key = PyLong_FromLong(obj->id);
! 	val = PyLong_FromLong((long)rv);
! 	PyDict_SetItem(threads, key, val);
! 	id = obj->id;
! 	free(obj);
! 	return id;
  }
  

Index: thread_os2.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/thread_os2.h,v
retrieving revision 2.10
retrieving revision 2.11
diff -C2 -d -r2.10 -r2.11
*** thread_os2.h	2000/09/01 23:29:28	2.10
--- thread_os2.h	2001/10/16 21:13:49	2.11
***************
*** 22,35 ****
   * Thread support.
   */
! int
  PyThread_start_new_thread(void (*func)(void *), void *arg)
  {
    int aThread;
!   int success = 1;
  
    aThread = _beginthread(func,NULL,65536,arg);
  
    if( aThread == -1 ) {
!     success = 0;
      fprintf(stderr,"aThread failed == %d",aThread);
      dprintf(("_beginthread failed. return %ld\n", errno));
--- 22,35 ----
   * Thread support.
   */
! long
  PyThread_start_new_thread(void (*func)(void *), void *arg)
  {
    int aThread;
!   int success = 0;
  
    aThread = _beginthread(func,NULL,65536,arg);
  
    if( aThread == -1 ) {
!     success = -1;
      fprintf(stderr,"aThread failed == %d",aThread);
      dprintf(("_beginthread failed. return %ld\n", errno));

Index: thread_pth.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/thread_pth.h,v
retrieving revision 2.7
retrieving revision 2.8
diff -C2 -d -r2.7 -r2.8
*** thread_pth.h	2000/10/12 20:58:32	2.7
--- thread_pth.h	2001/10/16 21:13:49	2.8
***************
*** 45,49 ****
  
  
! int PyThread_start_new_thread(void (*func)(void *), void *arg)
  {
  	pth_t th;
--- 45,49 ----
  
  
! long PyThread_start_new_thread(void (*func)(void *), void *arg)
  {
  	pth_t th;
***************
*** 57,61 ****
  				 );
  
! 	return th == NULL ? 0 : 1;
  }
  
--- 57,61 ----
  				 );
  
! 	return th;
  }
  

Index: thread_pthread.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/thread_pthread.h,v
retrieving revision 2.34
retrieving revision 2.35
diff -C2 -d -r2.34 -r2.35
*** thread_pthread.h	2001/10/15 14:34:42	2.34
--- thread_pthread.h	2001/10/16 21:13:49	2.35
***************
*** 144,148 ****
  
  
! int 
  PyThread_start_new_thread(void (*func)(void *), void *arg)
  {
--- 144,148 ----
  
  
! long
  PyThread_start_new_thread(void (*func)(void *), void *arg)
  {
***************
*** 211,215 ****
  #endif
  	}
! 	return success != 0 ? 0 : 1;
  }
  
--- 211,219 ----
  #endif
  	}
! #if SIZEOF_PTHREAD_T <= SIZEOF_LONG
! 	return (long) th;
! #else
! 	return (long) *(long *) &th;
! #endif
  }
  

Index: thread_sgi.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/thread_sgi.h,v
retrieving revision 2.14
retrieving revision 2.15
diff -C2 -d -r2.14 -r2.15
*** thread_sgi.h	2000/09/01 23:29:29	2.14
--- thread_sgi.h	2001/10/16 21:13:49	2.15
***************
*** 169,173 ****
  }
  
! int PyThread_start_new_thread(void (*func)(void *), void *arg)
  {
  #ifdef USE_DL
--- 169,173 ----
  }
  
! long PyThread_start_new_thread(void (*func)(void *), void *arg)
  {
  #ifdef USE_DL
***************
*** 224,228 ****
  	if (usunsetlock(count_lock) < 0)
  		perror("usunsetlock (count_lock)");
! 	return success < 0 ? 0 : 1;
  }
  
--- 224,228 ----
  	if (usunsetlock(count_lock) < 0)
  		perror("usunsetlock (count_lock)");
! 	return success;
  }
  

Index: thread_solaris.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/thread_solaris.h,v
retrieving revision 2.15
retrieving revision 2.16
diff -C2 -d -r2.15 -r2.16
*** thread_solaris.h	2000/09/01 23:29:29	2.15
--- thread_solaris.h	2001/10/16 21:13:49	2.16
***************
*** 37,43 ****
  
  
! int 
  PyThread_start_new_thread(void (*func)(void *), void *arg)
  {
  	struct func_arg *funcarg;
  	int success = 0;	/* init not needed when SOLARIS_THREADS and */
--- 37,44 ----
  
  
! long
  PyThread_start_new_thread(void (*func)(void *), void *arg)
  {
+ 	thread_t tid;
  	struct func_arg *funcarg;
  	int success = 0;	/* init not needed when SOLARIS_THREADS and */
***************
*** 51,60 ****
  	funcarg->arg = arg;
  	if (thr_create(0, 0, new_func, funcarg,
! 		       THR_DETACHED | THR_NEW_LWP, 0)) {
  		perror("thr_create");
  		free((void *) funcarg);
  		success = -1;
  	}
! 	return success < 0 ? 0 : 1;
  }
  
--- 52,61 ----
  	funcarg->arg = arg;
  	if (thr_create(0, 0, new_func, funcarg,
! 		       THR_DETACHED | THR_NEW_LWP, &tid)) {
  		perror("thr_create");
  		free((void *) funcarg);
  		success = -1;
  	}
! 	return tid;
  }
  

Index: thread_wince.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/thread_wince.h,v
retrieving revision 2.6
retrieving revision 2.7
diff -C2 -d -r2.6 -r2.7
*** thread_wince.h	2000/09/01 23:29:29	2.6
--- thread_wince.h	2001/10/16 21:13:49	2.7
***************
*** 23,30 ****
   * Thread support.
   */
! int PyThread_start_new_thread(void (*func)(void *), void *arg)
  {
  	long rv;
! 	int success = 0;
  
  	dprintf(("%ld: PyThread_start_new_thread called\n", PyThread_get_thread_ident()));
--- 23,30 ----
   * Thread support.
   */
! long PyThread_start_new_thread(void (*func)(void *), void *arg)
  {
  	long rv;
! 	int success = -1;
  
  	dprintf(("%ld: PyThread_start_new_thread called\n", PyThread_get_thread_ident()));
***************
*** 35,39 ****
   
  	if (rv != -1) {
! 		success = 1;
  		dprintf(("%ld: PyThread_start_new_thread succeeded:\n", PyThread_get_thread_ident()));
  	}
--- 35,39 ----
   
  	if (rv != -1) {
! 		success = 0;
  		dprintf(("%ld: PyThread_start_new_thread succeeded:\n", PyThread_get_thread_ident()));
  	}