diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-11-01 20:15:23 +0100 |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-11-01 20:15:23 +0100 |
commit | bb42f1ed9aeb4d9708fa57501bd208c8b5db2229 (patch) | |
tree | 3a8b6bf5dc17986078b94c5b7b9ab05cb2851076 /Python/thread_pthread.h | |
parent | 397dfac64f36bf0f9abf8f7969abf46925dda753 (diff) | |
parent | 99884cde16e365202fd4c9c591b90a5ae8008b36 (diff) | |
download | cpython-bb42f1ed9aeb4d9708fa57501bd208c8b5db2229.tar.gz |
Issue #16230: Fix a crash in select.select() when one the lists changes size while iterated on.
Patch by Serhiy Storchaka.
Diffstat (limited to 'Python/thread_pthread.h')
-rw-r--r-- | Python/thread_pthread.h | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h index 3cde03567c..5007aaf0b7 100644 --- a/Python/thread_pthread.h +++ b/Python/thread_pthread.h @@ -148,7 +148,7 @@ typedef struct { * Initialization. */ -#ifdef _HAVE_BSDI +#if defined(_HAVE_BSDI) static void _noop(void) { @@ -244,8 +244,7 @@ PyThread_start_new_thread(void (*func)(void *), void *arg) hosed" because: - It does not guarantee the promise that a non-zero integer is returned. - The cast to long is inherently unsafe. - - It is not clear that the 'volatile' (for AIX?) and ugly casting in the - latter return statement (for Alpha OSF/1) are any longer necessary. + - It is not clear that the 'volatile' (for AIX?) are any longer necessary. */ long PyThread_get_thread_ident(void) @@ -253,13 +252,8 @@ PyThread_get_thread_ident(void) volatile pthread_t threadid; if (!initialized) PyThread_init_thread(); - /* Jump through some hoops for Alpha OSF/1 */ threadid = pthread_self(); -#if SIZEOF_PTHREAD_T <= SIZEOF_LONG return (long) threadid; -#else - return (long) *(long *) &threadid; -#endif } void @@ -449,12 +443,15 @@ PyThread_free_lock(PyThread_type_lock lock) dprintf(("PyThread_free_lock(%p) called\n", lock)); - status = pthread_mutex_destroy( &thelock->mut ); - CHECK_STATUS("pthread_mutex_destroy"); - + /* some pthread-like implementations tie the mutex to the cond + * and must have the cond destroyed first. + */ status = pthread_cond_destroy( &thelock->lock_released ); CHECK_STATUS("pthread_cond_destroy"); + status = pthread_mutex_destroy( &thelock->mut ); + CHECK_STATUS("pthread_mutex_destroy"); + free((void *)thelock); } @@ -537,12 +534,12 @@ PyThread_release_lock(PyThread_type_lock lock) thelock->locked = 0; - status = pthread_mutex_unlock( &thelock->mut ); - CHECK_STATUS("pthread_mutex_unlock[3]"); - /* wake up someone (anyone, if any) waiting on the lock */ status = pthread_cond_signal( &thelock->lock_released ); CHECK_STATUS("pthread_cond_signal"); + + status = pthread_mutex_unlock( &thelock->mut ); + CHECK_STATUS("pthread_mutex_unlock[3]"); } #endif /* USE_SEMAPHORES */ |