1dnl
2dnl Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
3dnl                         University Research and Technology
4dnl                         Corporation.  All rights reserved.
5dnl Copyright (c) 2004-2005 The University of Tennessee and The University
6dnl                         of Tennessee Research Foundation.  All rights
7dnl                         reserved.
8dnl Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
9dnl                         University of Stuttgart.  All rights reserved.
10dnl Copyright (c) 2004-2005 The Regents of the University of California.
11dnl                         All rights reserved.
12dnl Copyright (c) 2008-2013 Cisco Systems, Inc.  All rights reserved.
13dnl $COPYRIGHT$
14dnl
15dnl Additional copyrights may follow
16dnl
17dnl $HEADER$
18dnl
19
20AC_DEFUN([OPAL_CHECK_PTHREAD_PIDS],[
21#
22# Arguments: none
23#
24# Dependencies: None
25#
26# Sets:
27#  OPAL_THREADS_HAVE_DIFFERENT_PIDS (variable)
28#
29# Test for Linux-like threads in the system.  OPAL no longer supports
30# systems with different PIDs for threads in the same process, so error
31# out if we detect that case.
32#
33
34AC_MSG_CHECKING([if threads have different pids (pthreads on linux)])
35
36OPAL_VAR_SCOPE_PUSH([CFLAGS_save CPPFLAGS_save LDFLAGS_save LIBS_save MSG])
37CFLAGS_save="$CFLAGS"
38CFLAGS="$CFLAGS $THREAD_CFLAGS"
39CPPFLAGS_save="$CPPFLAGS"
40CPPFLAGS="$CPPFLAGS $THREAD_CPPFLAGS"
41LDFLAGS_save="$LDFLAGS"
42LDFLAGS="$LDFLAGS $THREAD_LDFLAGS"
43LIBS_save="$LIBS"
44LIBS="$LIBS $THREAD_LIBS"
45AC_RUN_IFELSE([AC_LANG_SOURCE([#include <pthread.h>
46#include <sys/types.h>
47#include <unistd.h>
48#include <stdlib.h>
49
50void *checkpid(void *arg);
51int main() {
52  pthread_t thr;
53  int pid, *retval;
54  pid = getpid();
55  pthread_create(&thr, NULL, checkpid, &pid);
56  pthread_join(thr, (void **) &retval);
57  exit(*retval);
58}
59
60static int ret;
61void *checkpid(void *arg) {
62   int ppid = *((int *) arg);
63   if (ppid == getpid())
64     ret = 0;
65   else
66     ret = 1;
67   pthread_exit((void *) &ret);
68}])],
69[MSG=no OPAL_THREADS_HAVE_DIFFERENT_PIDS=0],
70[MSG=yes OPAL_THREADS_HAVE_DIFFERENT_PIDS=1],
71[
72 # If we're cross compiling, we can't do another AC_* function here beause
73 # it we haven't displayed the result from the last one yet.  So defer
74 # another test until below.
75 OPAL_THREADS_HAVE_DIFFERENT_PIDS=
76 MSG="cross compiling (need another test)"])
77
78CFLAGS="$CFLAGS_save"
79CPPFLAGS="$CPPFLAGS_save"
80LDFLAGS="$LDFLAGS_save"
81LIBS="$LIBS_save"
82
83AC_MSG_RESULT([$MSG])
84
85AS_IF([test "x$OPAL_THREADS_HAVE_DIFFERENT_PIDS" = "x"],
86      [ # If we are cross-compiling, look for the symbol
87       # __linuxthreads_create_event, which seems to only exist in the
88       # Linux Threads-based pthreads implementation (i.e., the one
89       # that has different PIDs for each thread).  We *could* switch
90       # on $host here and only test *linux* hosts, but this test is
91       # pretty unique, so why bother?  Note that AC_CHECK_FUNC works
92       # properly in cross-compiling environments in recent-enough
93       # versions of Autoconf (which is one of the reasons we mandate
94       # recent versions in autogen!).
95       AC_CHECK_FUNC([__linuxthreads_create_event],
96                     [OPAL_THREADS_HAVE_DIFFERENT_PIDS=1])])
97
98AS_IF([test "$OPAL_THREADS_HAVE_DIFFERENT_PIDS" = "1"],
99      [AC_MSG_WARN([This version of Open MPI only supports environments where])
100       AC_MSG_WARN([threads have the same PID.  Please use an older version of])
101       AC_MSG_WARN([Open MPI if you need support on systems with different])
102       AC_MSG_WARN([PIDs for threads in the same process.  Open MPI 1.4.x])
103       AC_MSG_WARN([supports such systems, as does at least some versions the])
104       AC_MSG_WARN([Open MPI 1.5.x series.])
105       AC_MSG_ERROR([Cannot continue])
106      ])
107
108#
109# if pthreads is not available, then the system does not have an insane threads
110# model
111#
112OPAL_VAR_SCOPE_POP])dnl
113