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

Skip to content

Commit d0b69ec

Browse files
committed
Improve threading on Solaris, according to SF patch #460269, submitted
by [email protected] / [email protected]. This adds a configure check and if all goes well turns on the PTHREAD_SCOPE_SYSTEM thread attribute for new threads. This should remove the need to add tiny sleeps at the start of threads to allow other threads to be scheduled.
1 parent 47f4034 commit d0b69ec

5 files changed

Lines changed: 324 additions & 224 deletions

File tree

Python/thread_pthread.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,21 @@ PyThread_start_new_thread(void (*func)(void *), void *arg)
135135
{
136136
pthread_t th;
137137
int success;
138-
#ifdef THREAD_STACK_SIZE
138+
#if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED)
139139
pthread_attr_t attrs;
140140
#endif
141141
dprintf(("PyThread_start_new_thread called\n"));
142142
if (!initialized)
143143
PyThread_init_thread();
144144

145-
#ifdef THREAD_STACK_SIZE
145+
#if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED)
146146
pthread_attr_init(&attrs);
147+
#endif
148+
#ifdef THREAD_STACK_SIZE
147149
pthread_attr_setstacksize(&attrs, THREAD_STACK_SIZE);
150+
#endif
151+
#ifdef PTHREAD_SYSTEM_SCHED_SUPPORTED
152+
pthread_attr_setscope(&attrs, PTHREAD_SCOPE_SYSTEM);
148153
#endif
149154
success = pthread_create(&th,
150155
#if defined(PY_PTHREAD_D4)
@@ -160,7 +165,7 @@ PyThread_start_new_thread(void (*func)(void *), void *arg)
160165
func,
161166
arg
162167
#elif defined(PY_PTHREAD_STD)
163-
#ifdef THREAD_STACK_SIZE
168+
#if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED)
164169
&attrs,
165170
#else
166171
(pthread_attr_t*)NULL,

acconfig.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@
155155
/* The number of bytes in a pthread_t. */
156156
#undef SIZEOF_PTHREAD_T
157157

158+
/* Defined if PTHREAD_SCOPE_SYSTEM supported. */
159+
#undef PTHREAD_SYSTEM_SCHED_SUPPORTED
160+
158161
/* sizeof(void *) */
159162
#undef SIZEOF_VOID_P
160163

0 commit comments

Comments
 (0)