+ if test $ac_cv_header_pthread_h = yes ; then
+ OL_POSIX_THREAD_VERSION
+
+ if test $ol_cv_pthread_version = final ; then
+ AC_DEFINE(HAVE_PTHREADS_FINAL)
+ elif test $ol_cv_pthread_version = draft4 ; then
+ AC_DEFINE(HAVE_PTHREADS_D4)
+ else
+ AC_MSG_ERROR([unknown pthread version])
+ fi
+
+ # consider threads found
+ ol_with_threads=found
+
+ OL_LINUX_THREADS
+
+ if test $ol_cv_linux_threads = yes ; then
+ AC_DEFINE(HAVE_LINUX_THREADS,1)
+ fi
+
+ dnl Now the hard part, how to link
+
+ dnl Check for pthread support in current $LIBS
+ AC_CHECK_FUNC(pthread_create,[ol_link_threads=yes])
+
+ if test $ol_link_threads = no ; then
+ dnl try -pthread
+ AC_CACHE_CHECK([for pthread_create with -pthread],
+ [ol_cv_pthread_flag], [
+ dnl save the flags
+ save_LIBS="$LIBS"
+ LIBS="-pthread $LIBS"
+ AC_TRY_LINK([char pthread();],[
+ pthread_create();
+ ], ol_cv_pthread_flag=yes, ol_cv_pthread_flag=no)
+ dnl restore the LIBS
+ LIBS="$save_LIBS"
+ ])
+
+ if test $ol_cv_pthread_flag = yes ; then
+ LTHREAD_LIBS="$LTHREAD_LIBS -pthread"
+ ol_link_threads=posix
+ fi
+ fi
+
+ if test $ol_link_threads = no ; then
+ dnl try -thread
+ AC_CACHE_CHECK([for pthread_create with -thread],
+ [ol_cv_thread_flag], [
+ dnl save the flags
+ save_LIBS="$LIBS"
+ LIBS="-thread $LIBS"
+ AC_TRY_LINK([char pthread();],[
+ pthread_create();
+ ], ol_cv_thread_flag=yes, ol_cv_thread_flag=no)
+ dnl restore the LIBS
+ LIBS="$save_LIBS"
+ ])
+
+ if test $ol_cv_thread_flag = yes ; then
+ LTHREAD_LIBS="$LTHREAD_LIBS -thread"
+ ol_link_threads=posix
+ fi
+ fi
+
+ if test $ol_link_threads = no ; then
+ dnl try DEC Threads -lpthread -lexc
+ save_LIBS="$LIBS"
+ AC_CHECK_LIB(pthread, pthread_join, [
+ ol_link_threads=posix
+ LTHREAD_LIBS="$LTHREAD_LIBS -lpthread -lexc"
+ if test $ol_with_yielding_select = auto ; then
+ ol_with_yielding_select=yes
+ fi
+ ],,[-lexc])
+ LIBS="$save_LIBS"
+ fi
+
+ if test $ol_link_threads = no ; then
+ dnl try DEC Threads -lpthreads -lmach -lexc -lc_r
+ save_LIBS="$LIBS"
+ AC_CHECK_LIB(pthreads, pthread_join, [
+ ol_link_threads=posix
+ LTHREAD_LIBS="$LTHREAD_LIBS -lpthreads -lmach -lexc -lc_r"
+ if test $ol_with_yielding_select = auto ; then
+ ol_with_yielding_select=yes
+ fi
+ ],,[-lmach -lexc -lc_r])
+ LIBS="$save_LIBS"
+ fi
+
+ if test $ol_link_threads = no ; then
+ dnl try -lpthread
+ save_LIBS="$LIBS"
+ AC_CHECK_LIB(pthread, pthread_create, [
+ ol_link_threads=posix
+ LTHREAD_LIBS="$LTHREAD_LIBS -lpthread"])
+ LIBS="$save_LIBS"
+ fi
+
+ if test $ol_link_threads = no ; then
+ dnl try -lc_r
+ save_LIBS="$LIBS"
+ AC_CHECK_LIB(c_r, pthread_create, [
+ ol_link_threads=posix
+ LTHREAD_LIBS="$LTHREAD_LIBS -lc_r"])
+ LIBS="$save_LIBS"
+ fi
+
+ if test $ol_link_threads != no ; then
+ AC_DEFINE(HAVE_PTHREADS)
+
+ dnl save flags
+ save_CPPFLAGS="$CPPFLAGS"
+ save_LIBS="$LIBS"
+ LIBS="$LTHREAD_LIBS $LIBS"
+
+ dnl All POSIX Thread (final) implementations should have
+ dnl sched_yield instead of pthread yield.
+ dnl check for both
+ AC_CHECK_FUNCS(sched_yield pthread_yield)
+
+ if test $ac_cv_func_sched_yield = no -a \
+ $ac_cv_func_pthread_yield = no ; then
+ dnl Digital UNIX has sched_yield() in -lrt
+ AC_CHECK_LIB(rt, sched_yield,
+ [LTHREAD_LIBS="$LTHREAD_LIBS -lrt"
+ AC_DEFINE(HAVE_SCHED_YIELD,1)
+ ac_cv_func_sched_yield=yes],
+ [ac_cv_func_sched_yield=no])
+ fi
+ if test $ac_cv_func_sched_yield = no -a \
+ $ac_cv_func_pthread_yield = no ; then
+ dnl Solaris has sched_yield() in -lposix4
+ AC_CHECK_LIB(posix4, sched_yield,
+ [LTHREAD_LIBS="$LTHREAD_LIBS -lposix4"
+ AC_DEFINE(HAVE_SCHED_YIELD,1)
+ ac_cv_func_sched_yield=yes],
+ [ac_cv_func_sched_yield=no])
+ fi
+ if test $ac_cv_func_sched_yield = no -a \
+ $ac_cv_func_pthread_yield = no ; then
+ AC_MSG_WARN([could not locate sched_yield() or pthread_yield()])
+ AC_MSG_ERROR([POSIX Threads are not usable])
+ fi
+
+ dnl Check functions for compatibility
+ AC_CHECK_FUNCS(pthread_kill)
+ AC_CHECK_FUNCS( \
+ pthread_attr_create pthread_attr_init \
+ pthread_attr_destroy pthread_attr_delete \
+ pthread_attr_setdetachstate pthread_attr_setdetach_np \
+ )
+
+ dnl Check for setconcurreny functions
+ AC_CHECK_FUNCS( \
+ pthread_setconcurrency \
+ thr_setconcurrency \
+ )
+
+ AC_MSG_CHECKING([if pthread_create() works])
+ AC_CACHE_VAL(ol_cv_pthread_create_works,[
+ AC_TRY_RUN([