File: pmix_check_pthread_pids.m4

package info (click to toggle)
openmpi 5.0.8-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 201,684 kB
  • sloc: ansic: 613,078; makefile: 42,353; sh: 11,194; javascript: 9,244; f90: 7,052; java: 6,404; perl: 5,179; python: 1,859; lex: 740; fortran: 61; cpp: 20; tcl: 12
file content (109 lines) | stat: -rw-r--r-- 3,703 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
dnl
dnl Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
dnl                         University Research and Technology
dnl                         Corporation.  All rights reserved.
dnl Copyright (c) 2004-2005 The University of Tennessee and The University
dnl                         of Tennessee Research Foundation.  All rights
dnl                         reserved.
dnl Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
dnl                         University of Stuttgart.  All rights reserved.
dnl Copyright (c) 2004-2005 The Regents of the University of California.
dnl                         All rights reserved.
dnl Copyright (c) 2008-2013 Cisco Systems, Inc.  All rights reserved.
dnl Copyright (c) 2017      Intel, Inc. All rights reserved.
dnl $COPYRIGHT$
dnl
dnl Additional copyrights may follow
dnl
dnl $HEADER$
dnl

AC_DEFUN([PMIX_CHECK_PTHREAD_PIDS],[
#
# Arguments: none
#
# Dependencies: None
#
# Sets:
#  PMIX_THREADS_HAVE_DIFFERENT_PIDS (variable)
#
# Test for Linux-like threads in the system.  PMIX does not support
# systems with different PIDs for threads in the same process, so error
# out if we detect that case.
#

AC_MSG_CHECKING([if threads have different pids (pthreads on linux)])

PMIX_VAR_SCOPE_PUSH([tpids_CFLAGS_save tpids_CPPFLAGS_save tpids_LDFLAGS_save tpids_LIBS_save tpids_MSG])
tpids_CFLAGS_save="$CFLAGS"
CFLAGS="$CFLAGS $THREAD_CFLAGS"
tpids_CPPFLAGS_save="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $THREAD_CPPFLAGS"
tpids_LDFLAGS_save="$LDFLAGS"
LDFLAGS="$LDFLAGS $THREAD_LDFLAGS"
tpids_LIBS_save="$LIBS"
LIBS="$LIBS $THREAD_LIBS"
AC_RUN_IFELSE([AC_LANG_SOURCE([#include <pthread.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>

void *checkpid(void *arg);
int main(void) {
  pthread_t thr;
  int pid, *retval;
  pid = getpid();
  pthread_create(&thr, NULL, checkpid, &pid);
  pthread_join(thr, (void **) &retval);
  exit(*retval);
}

static int ret;
void *checkpid(void *arg) {
   int ppid = *((int *) arg);
   if (ppid == getpid())
     ret = 0;
   else
     ret = 1;
   pthread_exit((void *) &ret);
}])],
[tpids_MSG=no PMIX_THREADS_HAVE_DIFFERENT_PIDS=0],
[tpids_MSG=yes PMIX_THREADS_HAVE_DIFFERENT_PIDS=1],
[
 # If we're cross compiling, we can't do another AC_* function here because
 # it we haven't displayed the result from the last one yet.  So defer
 # another test until below.
 PMIX_THREADS_HAVE_DIFFERENT_PIDS=
 MSG="cross compiling (need another test)"])

CFLAGS="$tpids_CFLAGS_save"
CPPFLAGS="$tpids_CPPFLAGS_save"
LDFLAGS="$tpids_LDFLAGS_save"
LIBS="$tpids_LIBS_save"

AC_MSG_RESULT([$tpids_MSG])

AS_IF([test "x$PMIX_THREADS_HAVE_DIFFERENT_PIDS" = "x"],
      [ # If we are cross-compiling, look for the symbol
       # __linuxthreads_create_event, which seems to only exist in the
       # Linux Threads-based pthreads implementation (i.e., the one
       # that has different PIDs for each thread).  We *could* switch
       # on $host here and only test *linux* hosts, but this test is
       # pretty unique, so why bother?  Note that AC_CHECK_FUNC works
       # properly in cross-compiling environments in recent-enough
       # versions of Autoconf (which is one of the reasons we mandate
       # recent versions in autogen!).
       AC_CHECK_FUNC([__linuxthreads_create_event],
                     [PMIX_THREADS_HAVE_DIFFERENT_PIDS=1])])

AS_IF([test "$PMIX_THREADS_HAVE_DIFFERENT_PIDS" = "1"],
      [AC_MSG_WARN([This version of PMIx only supports environments where])
       AC_MSG_WARN([threads have the same PID])
       AC_MSG_ERROR([Cannot continue])
      ])

#
# if pthreads is not available, then the system does not have an insane threads
# model
#
PMIX_VAR_SCOPE_POP])dnl