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.
This commit is contained in:
Guido van Rossum 2001-09-10 14:10:54 +00:00
parent 47f40343b3
commit d0b69eceb4
5 changed files with 376 additions and 276 deletions

View File

@ -135,16 +135,21 @@ PyThread_start_new_thread(void (*func)(void *), void *arg)
{
pthread_t th;
int success;
#ifdef THREAD_STACK_SIZE
#if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED)
pthread_attr_t attrs;
#endif
dprintf(("PyThread_start_new_thread called\n"));
if (!initialized)
PyThread_init_thread();
#ifdef THREAD_STACK_SIZE
#if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED)
pthread_attr_init(&attrs);
#endif
#ifdef THREAD_STACK_SIZE
pthread_attr_setstacksize(&attrs, THREAD_STACK_SIZE);
#endif
#ifdef PTHREAD_SYSTEM_SCHED_SUPPORTED
pthread_attr_setscope(&attrs, PTHREAD_SCOPE_SYSTEM);
#endif
success = pthread_create(&th,
#if defined(PY_PTHREAD_D4)
@ -160,7 +165,7 @@ PyThread_start_new_thread(void (*func)(void *), void *arg)
func,
arg
#elif defined(PY_PTHREAD_STD)
#ifdef THREAD_STACK_SIZE
#if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED)
&attrs,
#else
(pthread_attr_t*)NULL,

View File

@ -155,6 +155,9 @@
/* The number of bytes in a pthread_t. */
#undef SIZEOF_PTHREAD_T
/* Defined if PTHREAD_SCOPE_SYSTEM supported. */
#undef PTHREAD_SYSTEM_SCHED_SUPPORTED
/* sizeof(void *) */
#undef SIZEOF_VOID_P

596
configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -903,6 +903,7 @@ then
CC="$CC -Kpthread"
AC_DEFINE(WITH_THREAD)
AC_DEFINE(_POSIX_THREADS)
posix_threads=yes
LIBOBJS="$LIBOBJS thread.o"
else
if test ! -z "$with_threads" -a -d "$with_threads"
@ -927,14 +928,18 @@ else
AC_CHECK_LIB(pthread, pthread_create, [AC_DEFINE(WITH_THREAD)
case $ac_sys_system in
Darwin*) ;;
*) AC_DEFINE(_POSIX_THREADS);;
*) AC_DEFINE(_POSIX_THREADS)
posix_threads=yes
;;
esac
LIBS="-lpthread $LIBS"
LIBOBJS="$LIBOBJS thread.o"],[
AC_CHECK_FUNC(pthread_detach, [AC_DEFINE(WITH_THREAD)
case $ac_sys_system in
Darwin*) ;;
*) AC_DEFINE(_POSIX_THREADS);;
*) AC_DEFINE(_POSIX_THREADS)
posix_threads=yes
;;
esac
LIBOBJS="$LIBOBJS thread.o"],[
AC_CHECK_HEADER(kernel/OS.h, [AC_DEFINE(WITH_THREAD)
@ -942,27 +947,53 @@ else
LIBOBJS="$LIBOBJS thread.o"],[
AC_CHECK_LIB(pthreads, pthread_create, [AC_DEFINE(WITH_THREAD)
AC_DEFINE(_POSIX_THREADS)
posix_threads=yes
LIBS="$LIBS -lpthreads"
LIBOBJS="$LIBOBJS thread.o"], [
AC_CHECK_LIB(c_r, pthread_create, [AC_DEFINE(WITH_THREAD)
AC_DEFINE(_POSIX_THREADS)
posix_threads=yes
LIBS="$LIBS -lc_r"
LIBOBJS="$LIBOBJS thread.o"], [
AC_CHECK_LIB(thread, __d6_pthread_create, [AC_DEFINE(WITH_THREAD)
AC_DEFINE(_POSIX_THREADS)
posix_threads=yes
LIBS="$LIBS -lthread"
LIBOBJS="$LIBOBJS thread.o"], [
AC_CHECK_LIB(pthread, __pthread_create_system, [AC_DEFINE(WITH_THREAD)
AC_DEFINE(_POSIX_THREADS)
posix_threads=yes
LIBS="$LIBS -lpthread"
LIBOBJS="$LIBOBJS thread.o"], [
AC_CHECK_LIB(cma, pthread_create, [AC_DEFINE(WITH_THREAD)
AC_DEFINE(_POSIX_THREADS)
posix_threads=yes
LIBS="$LIBS -lcma"
LIBOBJS="$LIBOBJS thread.o"],[
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)
LIBS="$LIBS -lmpc"
LIBOBJS="$LIBOBJS thread.o"

View File

@ -214,6 +214,9 @@
/* The number of bytes in a 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. */
#undef socklen_t