Kaydet (Commit) d0b69ece authored tarafından Guido van Rossum's avatar Guido van Rossum

Improve threading on Solaris, according to SF patch #460269, submitted

by bbrox@bbrox.org / lionel.ulmer@free.fr.

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.
üst 47f40343
...@@ -135,16 +135,21 @@ PyThread_start_new_thread(void (*func)(void *), void *arg) ...@@ -135,16 +135,21 @@ PyThread_start_new_thread(void (*func)(void *), void *arg)
{ {
pthread_t th; pthread_t th;
int success; int success;
#ifdef THREAD_STACK_SIZE #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED)
pthread_attr_t attrs; pthread_attr_t attrs;
#endif #endif
dprintf(("PyThread_start_new_thread called\n")); dprintf(("PyThread_start_new_thread called\n"));
if (!initialized) if (!initialized)
PyThread_init_thread(); PyThread_init_thread();
#ifdef THREAD_STACK_SIZE #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED)
pthread_attr_init(&attrs); pthread_attr_init(&attrs);
#endif
#ifdef THREAD_STACK_SIZE
pthread_attr_setstacksize(&attrs, THREAD_STACK_SIZE); pthread_attr_setstacksize(&attrs, THREAD_STACK_SIZE);
#endif
#ifdef PTHREAD_SYSTEM_SCHED_SUPPORTED
pthread_attr_setscope(&attrs, PTHREAD_SCOPE_SYSTEM);
#endif #endif
success = pthread_create(&th, success = pthread_create(&th,
#if defined(PY_PTHREAD_D4) #if defined(PY_PTHREAD_D4)
...@@ -160,7 +165,7 @@ PyThread_start_new_thread(void (*func)(void *), void *arg) ...@@ -160,7 +165,7 @@ PyThread_start_new_thread(void (*func)(void *), void *arg)
func, func,
arg arg
#elif defined(PY_PTHREAD_STD) #elif defined(PY_PTHREAD_STD)
#ifdef THREAD_STACK_SIZE #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED)
&attrs, &attrs,
#else #else
(pthread_attr_t*)NULL, (pthread_attr_t*)NULL,
......
...@@ -155,6 +155,9 @@ ...@@ -155,6 +155,9 @@
/* The number of bytes in a pthread_t. */ /* The number of bytes in a pthread_t. */
#undef SIZEOF_PTHREAD_T #undef SIZEOF_PTHREAD_T
/* Defined if PTHREAD_SCOPE_SYSTEM supported. */
#undef PTHREAD_SYSTEM_SCHED_SUPPORTED
/* sizeof(void *) */ /* sizeof(void *) */
#undef SIZEOF_VOID_P #undef SIZEOF_VOID_P
......
This diff is collapsed.
...@@ -903,6 +903,7 @@ then ...@@ -903,6 +903,7 @@ then
CC="$CC -Kpthread" CC="$CC -Kpthread"
AC_DEFINE(WITH_THREAD) AC_DEFINE(WITH_THREAD)
AC_DEFINE(_POSIX_THREADS) AC_DEFINE(_POSIX_THREADS)
posix_threads=yes
LIBOBJS="$LIBOBJS thread.o" LIBOBJS="$LIBOBJS thread.o"
else else
if test ! -z "$with_threads" -a -d "$with_threads" if test ! -z "$with_threads" -a -d "$with_threads"
...@@ -927,14 +928,18 @@ else ...@@ -927,14 +928,18 @@ else
AC_CHECK_LIB(pthread, pthread_create, [AC_DEFINE(WITH_THREAD) AC_CHECK_LIB(pthread, pthread_create, [AC_DEFINE(WITH_THREAD)
case $ac_sys_system in case $ac_sys_system in
Darwin*) ;; Darwin*) ;;
*) AC_DEFINE(_POSIX_THREADS);; *) AC_DEFINE(_POSIX_THREADS)
posix_threads=yes
;;
esac esac
LIBS="-lpthread $LIBS" LIBS="-lpthread $LIBS"
LIBOBJS="$LIBOBJS thread.o"],[ LIBOBJS="$LIBOBJS thread.o"],[
AC_CHECK_FUNC(pthread_detach, [AC_DEFINE(WITH_THREAD) AC_CHECK_FUNC(pthread_detach, [AC_DEFINE(WITH_THREAD)
case $ac_sys_system in case $ac_sys_system in
Darwin*) ;; Darwin*) ;;
*) AC_DEFINE(_POSIX_THREADS);; *) AC_DEFINE(_POSIX_THREADS)
posix_threads=yes
;;
esac esac
LIBOBJS="$LIBOBJS thread.o"],[ LIBOBJS="$LIBOBJS thread.o"],[
AC_CHECK_HEADER(kernel/OS.h, [AC_DEFINE(WITH_THREAD) AC_CHECK_HEADER(kernel/OS.h, [AC_DEFINE(WITH_THREAD)
...@@ -942,27 +947,53 @@ else ...@@ -942,27 +947,53 @@ else
LIBOBJS="$LIBOBJS thread.o"],[ LIBOBJS="$LIBOBJS thread.o"],[
AC_CHECK_LIB(pthreads, pthread_create, [AC_DEFINE(WITH_THREAD) AC_CHECK_LIB(pthreads, pthread_create, [AC_DEFINE(WITH_THREAD)
AC_DEFINE(_POSIX_THREADS) AC_DEFINE(_POSIX_THREADS)
posix_threads=yes
LIBS="$LIBS -lpthreads" LIBS="$LIBS -lpthreads"
LIBOBJS="$LIBOBJS thread.o"], [ LIBOBJS="$LIBOBJS thread.o"], [
AC_CHECK_LIB(c_r, pthread_create, [AC_DEFINE(WITH_THREAD) AC_CHECK_LIB(c_r, pthread_create, [AC_DEFINE(WITH_THREAD)
AC_DEFINE(_POSIX_THREADS) AC_DEFINE(_POSIX_THREADS)
posix_threads=yes
LIBS="$LIBS -lc_r" LIBS="$LIBS -lc_r"
LIBOBJS="$LIBOBJS thread.o"], [ LIBOBJS="$LIBOBJS thread.o"], [
AC_CHECK_LIB(thread, __d6_pthread_create, [AC_DEFINE(WITH_THREAD) AC_CHECK_LIB(thread, __d6_pthread_create, [AC_DEFINE(WITH_THREAD)
AC_DEFINE(_POSIX_THREADS) AC_DEFINE(_POSIX_THREADS)
posix_threads=yes
LIBS="$LIBS -lthread" LIBS="$LIBS -lthread"
LIBOBJS="$LIBOBJS thread.o"], [ LIBOBJS="$LIBOBJS thread.o"], [
AC_CHECK_LIB(pthread, __pthread_create_system, [AC_DEFINE(WITH_THREAD) AC_CHECK_LIB(pthread, __pthread_create_system, [AC_DEFINE(WITH_THREAD)
AC_DEFINE(_POSIX_THREADS) AC_DEFINE(_POSIX_THREADS)
posix_threads=yes
LIBS="$LIBS -lpthread" LIBS="$LIBS -lpthread"
LIBOBJS="$LIBOBJS thread.o"], [ LIBOBJS="$LIBOBJS thread.o"], [
AC_CHECK_LIB(cma, pthread_create, [AC_DEFINE(WITH_THREAD) AC_CHECK_LIB(cma, pthread_create, [AC_DEFINE(WITH_THREAD)
AC_DEFINE(_POSIX_THREADS) AC_DEFINE(_POSIX_THREADS)
posix_threads=yes
LIBS="$LIBS -lcma" LIBS="$LIBS -lcma"
LIBOBJS="$LIBOBJS thread.o"],[ LIBOBJS="$LIBOBJS thread.o"],[
USE_THREAD_MODULE="#"]) USE_THREAD_MODULE="#"])
])])])])])])])])]) ])])])])])])])])])
if test "$posix_threads" = "yes"; then
AC_MSG_CHECKING(if PTHREAD_SCOPE_SYSTEM is supported)
AC_CACHE_VAL(ac_cv_pthread_system_supported,
[AC_TRY_RUN([#include <pthread.h>
void *foo(void *parm) {
return NULL;
}
main() {
pthread_attr_t attr;
if (pthread_attr_init(&attr)) exit(-1);
if (pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM)) exit(-1);
if (pthread_create(NULL, &attr, foo, NULL)) exit(-1);
exit(0);
}], ac_cv_pthread_system_supported=yes, ac_cv_pthread_system_supported=no)
])
AC_MSG_RESULT($ac_cv_pthread_system_supported)
if test "$ac_cv_pthread_system_supported" = "yes"; then
AC_DEFINE(PTHREAD_SYSTEM_SCHED_SUPPORTED)
fi
fi
AC_CHECK_LIB(mpc, usconfig, [AC_DEFINE(WITH_THREAD) AC_CHECK_LIB(mpc, usconfig, [AC_DEFINE(WITH_THREAD)
LIBS="$LIBS -lmpc" LIBS="$LIBS -lmpc"
LIBOBJS="$LIBOBJS thread.o" LIBOBJS="$LIBOBJS thread.o"
......
...@@ -214,6 +214,9 @@ ...@@ -214,6 +214,9 @@
/* The number of bytes in a pthread_t. */ /* The number of bytes in a pthread_t. */
#undef SIZEOF_PTHREAD_T #undef SIZEOF_PTHREAD_T
/* Defined if PTHREAD_SCOPE_SYSTEM supported. */
#undef PTHREAD_SYSTEM_SCHED_SUPPORTED
/* Define to `int' if <sys/types.h> doesn't define. */ /* Define to `int' if <sys/types.h> doesn't define. */
#undef socklen_t #undef socklen_t
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment