Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 910ae62

Browse files
committed
Patch #716969: Detect thread creation failure. Will backport to 2.2.
1 parent 1e91d8e commit 910ae62

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

Python/thread_pthread.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ long
188188
PyThread_start_new_thread(void (*func)(void *), void *arg)
189189
{
190190
pthread_t th;
191-
int success;
191+
int status;
192192
sigset_t oldmask, newmask;
193193
#if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED)
194194
pthread_attr_t attrs;
@@ -214,7 +214,7 @@ PyThread_start_new_thread(void (*func)(void *), void *arg)
214214
sigfillset(&newmask);
215215
SET_THREAD_SIGMASK(SIG_BLOCK, &newmask, &oldmask);
216216

217-
success = pthread_create(&th,
217+
status = pthread_create(&th,
218218
#if defined(PY_PTHREAD_D4)
219219
pthread_attr_default,
220220
(pthread_startroutine_t)func,
@@ -244,13 +244,15 @@ PyThread_start_new_thread(void (*func)(void *), void *arg)
244244
#if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED)
245245
pthread_attr_destroy(&attrs);
246246
#endif
247-
if (success == 0) {
247+
if (status != 0)
248+
return -1;
249+
248250
#if defined(PY_PTHREAD_D4) || defined(PY_PTHREAD_D6) || defined(PY_PTHREAD_D7)
249-
pthread_detach(&th);
251+
pthread_detach(&th);
250252
#elif defined(PY_PTHREAD_STD)
251-
pthread_detach(th);
253+
pthread_detach(th);
252254
#endif
253-
}
255+
254256
#if SIZEOF_PTHREAD_T <= SIZEOF_LONG
255257
return (long) th;
256258
#else

Python/thread_solaris.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ PyThread_start_new_thread(void (*func)(void *), void *arg)
4040
{
4141
thread_t tid;
4242
struct func_arg *funcarg;
43-
int success = 0; /* init not needed when SOLARIS_THREADS and */
44-
/* C_THREADS implemented properly */
4543

4644
dprintf(("PyThread_start_new_thread called\n"));
4745
if (!initialized)
@@ -53,7 +51,7 @@ PyThread_start_new_thread(void (*func)(void *), void *arg)
5351
THR_DETACHED | THR_NEW_LWP, &tid)) {
5452
perror("thr_create");
5553
free((void *) funcarg);
56-
success = -1;
54+
return -1;
5755
}
5856
return tid;
5957
}

0 commit comments

Comments
 (0)