+2019-07-14 Bruno Haible <bruno@clisp.org>
+
+ pthread-thread: New module.
+ * lib/pthread.in.h (pthread_create, pthread_exit, pthread_join): Remove
+ inline definitions.
+ * lib/pthread-thread.c: New file.
+ * m4/pthread-thread.m4: New file.
+ * modules/pthread-thread: New file.
+ * doc/posix-functions/pthread_create.texi: Mention the new module.
+ * doc/posix-functions/pthread_attr_init.texi: Likewise.
+ * doc/posix-functions/pthread_attr_getdetachstate.texi: Likewise.
+ * doc/posix-functions/pthread_attr_setdetachstate.texi: Likewise.
+ * doc/posix-functions/pthread_attr_destroy.texi: Likewise.
+ * doc/posix-functions/pthread_self.texi: Likewise.
+ * doc/posix-functions/pthread_equal.texi: Likewise.
+ * doc/posix-functions/pthread_detach.texi: Likewise.
+ * doc/posix-functions/pthread_join.texi: Likewise.
+ * doc/posix-functions/pthread_exit.texi: Likewise.
+
2019-07-14 Bruno Haible <bruno@clisp.org>
pthread-h: Prepare for adding new modules.
POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_destroy.html}
-Gnulib module: ---
+Gnulib module: pthread-thread
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on some platforms:
+Minix 3.1.8, mingw, MSVC 14.
+But the provided replacement is just a dummy on some of these platforms:
+Minix 3.1.8.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
-@item
-This function is missing on some platforms:
-Minix 3.1.8, HP-UX 11, mingw, MSVC 14.
@end itemize
POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getdetachstate.html}
-Gnulib module: ---
+Gnulib module: pthread-thread
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on some platforms:
+Minix 3.1.8, mingw, MSVC 14.
+But the provided replacement is just a dummy on some of these platforms:
+Minix 3.1.8.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
-@item
-This function is missing on some platforms:
-Minix 3.1.8, HP-UX 11, mingw, MSVC 14.
@end itemize
POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_init.html}
-Gnulib module: ---
+Gnulib module: pthread-thread
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on some platforms:
+Minix 3.1.8, mingw, MSVC 14.
+But the provided replacement is just a dummy on some of these platforms:
+Minix 3.1.8.
+@item
+This function is only defined as an inline function on some platforms:
+HP-UX 11.11.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
-@item
-This function is missing on some platforms:
-Minix 3.1.8, HP-UX 11.11, mingw, MSVC 14.
@end itemize
POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_setdetachstate.html}
-Gnulib module: ---
+Gnulib module: pthread-thread
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on some platforms:
+Minix 3.1.8, mingw, MSVC 14.
+But the provided replacement is just a dummy on some of these platforms:
+Minix 3.1.8.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
-@item
-This function is missing on some platforms:
-Minix 3.1.8, HP-UX 11, mingw, MSVC 14.
@end itemize
POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_create.html}
-Gnulib module: ---
+Gnulib module: pthread-thread
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on some platforms:
+Minix 3.1.8, mingw, MSVC 14.
+But the provided replacement is just a dummy on some of these platforms:
+Minix 3.1.8.
+@item
+This function is only defined as an inline function on some platforms:
+HP-UX 11.11.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
@item
-This function is missing on some platforms:
-Minix 3.1.8, HP-UX 11.11, mingw, MSVC 14.
-@item
-On Linux/glibc platforms before the advent of NPTL, signals could only be
-sent to one particular thread. In POSIX, signals are sent to the entire
+On Linux/glibc platforms before the advent of NPTL in 2003, signals could only
+be sent to one particular thread. In POSIX, signals are sent to the entire
process and executed by any thread of the process that happens to have the
particular signal currently unblocked.
@end itemize
POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_detach.html}
-Gnulib module: ---
+Gnulib module: pthread-thread
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on some platforms:
+Minix 3.1.8, mingw, MSVC 14.
+But the provided replacement is just a dummy on some of these platforms:
+Minix 3.1.8.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
-@item
-This function is missing on some platforms:
-Minix 3.1.8, mingw, MSVC 14.
@end itemize
POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_equal.html}
-Gnulib module: ---
+Gnulib module: pthread-thread
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on some platforms:
+Minix 3.1.8, mingw, MSVC 14.
+But the provided replacement is just a dummy on some of these platforms:
+Minix 3.1.8.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
-@item
-This function is missing on some platforms:
-Minix 3.1.8, mingw, MSVC 14.
@end itemize
POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_exit.html}
-Gnulib module: ---
+Gnulib module: pthread-thread
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on some platforms:
+Minix 3.1.8, mingw, MSVC 14.
+But the provided replacement is just a dummy on some of these platforms:
+Minix 3.1.8.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
-@item
-This function is missing on some platforms:
-Minix 3.1.8, mingw, MSVC 14.
@end itemize
POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_join.html}
-Gnulib module: ---
+Gnulib module: pthread-thread
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on some platforms:
+Minix 3.1.8, mingw, MSVC 14.
+But the provided replacement is just a dummy on some of these platforms:
+Minix 3.1.8.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
-@item
-This function is missing on some platforms:
-Minix 3.1.8, mingw, MSVC 14.
@end itemize
POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_self.html}
-Gnulib module: ---
+Gnulib module: pthread-thread
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on some platforms:
+Minix 3.1.8, mingw, MSVC 14.
+But the provided replacement is just a dummy on some of these platforms:
+Minix 3.1.8.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
-@item
-This function is missing on some platforms:
-Minix 3.1.8, mingw, MSVC 14.
@end itemize
--- /dev/null
+/* Creating and controlling POSIX threads.
+ Copyright (C) 2010-2019 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <https://www.gnu.org/licenses/>. */
+
+/* Written by Paul Eggert, 2010, and Bruno Haible <bruno@clisp.org>, 2019. */
+
+#include <config.h>
+
+/* Specification. */
+#include <pthread.h>
+
+#if (defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS
+# include "windows-thread.h"
+#else
+# include <stdlib.h>
+#endif
+
+typedef void * (* pthread_main_function_t) (void *);
+
+#if ((defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS) || !HAVE_PTHREAD_H
+
+int
+pthread_attr_init (pthread_attr_t *attr)
+{
+ *attr = PTHREAD_CREATE_JOINABLE;
+ return 0;
+}
+
+int
+pthread_attr_getdetachstate (pthread_attr_t *attr, int *detachstatep)
+{
+ *detachstatep = *attr & (PTHREAD_CREATE_JOINABLE | PTHREAD_CREATE_DETACHED);
+ return 0;
+}
+
+int
+pthread_attr_setdetachstate (pthread_attr_t *attr, int detachstate)
+{
+ if (!(detachstate == PTHREAD_CREATE_JOINABLE
+ || detachstate == PTHREAD_CREATE_DETACHED))
+ return EINVAL;
+ *attr ^= (*attr ^ detachstate)
+ & (PTHREAD_CREATE_JOINABLE | PTHREAD_CREATE_DETACHED);
+ return 0;
+}
+
+int
+pthread_attr_destroy (pthread_attr_t *attr _GL_UNUSED)
+{
+ return 0;
+}
+
+#endif
+
+#if (defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS
+/* Use Windows threads. */
+
+int
+pthread_create (pthread_t *threadp, const pthread_attr_t *attr,
+ pthread_main_function_t mainfunc, void *arg)
+{
+ unsigned int glwthread_attr =
+ (attr != NULL
+ && (*attr & (PTHREAD_CREATE_JOINABLE | PTHREAD_CREATE_DETACHED))
+ != PTHREAD_CREATE_JOINABLE
+ ? GLWTHREAD_ATTR_DETACHED
+ : 0);
+ return glwthread_thread_create (threadp, glwthread_attr, mainfunc, arg);
+}
+
+pthread_t
+pthread_self (void)
+{
+ return glwthread_thread_self ();
+}
+
+int
+pthread_equal (pthread_t thread1, pthread_t thread2)
+{
+ return thread1 == thread2;
+}
+
+int
+pthread_detach (pthread_t thread)
+{
+ return glwthread_thread_detach (thread);
+}
+
+int
+pthread_join (pthread_t thread, void **valuep)
+{
+ return glwthread_thread_join (thread, valuep);
+}
+
+void
+pthread_exit (void *value)
+{
+ glwthread_thread_exit (value);
+}
+
+#elif HAVE_PTHREAD_H
+/* Provide workarounds for POSIX threads. */
+
+# if PTHREAD_CREATE_IS_INLINE
+int
+pthread_create (pthread_t *threadp, const pthread_attr_t *attr,
+ pthread_main_function_t mainfunc, void *arg)
+# undef pthread_create
+{
+ return pthread_create (threadp, attr, mainfunc, arg);
+}
+
+int
+pthread_attr_init (pthread_attr_t *attr)
+# undef pthread_attr_init
+{
+ return pthread_attr_init (attr);
+}
+
+# endif
+
+#else
+/* Provide a dummy implementation for single-threaded applications. */
+
+int
+pthread_create (pthread_t *threadp, const pthread_attr_t *attr,
+ pthread_main_function_t mainfunc, void *arg)
+{
+ /* The maximum number of threads is reached. Do not create a thread. */
+ return EAGAIN;
+}
+
+pthread_t
+pthread_self (void)
+{
+ return 42;
+}
+
+int
+pthread_equal (pthread_t thread1, pthread_t thread2)
+{
+ return thread1 == thread2;
+}
+
+int
+pthread_detach (pthread_t thread)
+{
+ /* There are no joinable threads. */
+ return EINVAL;
+}
+
+int
+pthread_join (pthread_t thread, void **valuep)
+{
+ /* There are no joinable threads. */
+ return EINVAL;
+}
+
+void
+pthread_exit (void *value)
+{
+ /* There is just one thread, so the process exits. */
+ exit (0);
+}
+
+#endif
return 0;
}
-_GL_PTHREAD_INLINE int
-pthread_create (pthread_t *restrict thread,
- pthread_attr_t const *restrict attr,
- void * (*start_routine) (void*), void *restrict arg)
-{
- /* Do not create a thread. */
- return EAGAIN;
-}
-
-_GL_PTHREAD_INLINE void
-pthread_exit (void *value)
-{
- /* There is just one thread, so the process exits. */
- exit (0);
-}
-
-_GL_PTHREAD_INLINE int
-pthread_join (pthread_t thread, void **pvalue)
-{
- /* Properly-written applications never come here. */
- abort ();
- return 0;
-}
-
_GL_PTHREAD_INLINE int
pthread_mutexattr_destroy (pthread_mutexattr_t *attr)
{
--- /dev/null
+# pthread-thread.m4 serial 1
+dnl Copyright (C) 2019 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_PTHREAD_THREAD],
+[
+ AC_REQUIRE([gl_PTHREAD_H])
+ AC_REQUIRE([AC_CANONICAL_HOST])
+
+ if { case "$host_os" in mingw*) true;; *) false;; esac; } \
+ && test $gl_threads_api = windows; then
+ dnl Choose function names that don't conflict with the mingw-w64 winpthreads
+ dnl library.
+ REPLACE_PTHREAD_CREATE=1
+ REPLACE_PTHREAD_ATTR_INIT=1
+ REPLACE_PTHREAD_ATTR_GETDETACHSTATE=1
+ REPLACE_PTHREAD_ATTR_SETDETACHSTATE=1
+ REPLACE_PTHREAD_ATTR_DESTROY=1
+ REPLACE_PTHREAD_SELF=1
+ REPLACE_PTHREAD_EQUAL=1
+ REPLACE_PTHREAD_DETACH=1
+ REPLACE_PTHREAD_JOIN=1
+ REPLACE_PTHREAD_EXIT=1
+ else
+ if test $HAVE_PTHREAD_H = 0; then
+ HAVE_PTHREAD_CREATE=0
+ HAVE_PTHREAD_ATTR_INIT=0
+ HAVE_PTHREAD_ATTR_GETDETACHSTATE=0
+ HAVE_PTHREAD_ATTR_SETDETACHSTATE=0
+ HAVE_PTHREAD_ATTR_DESTROY=0
+ HAVE_PTHREAD_SELF=0
+ HAVE_PTHREAD_EQUAL=0
+ HAVE_PTHREAD_DETACH=0
+ HAVE_PTHREAD_JOIN=0
+ HAVE_PTHREAD_EXIT=0
+ else
+ dnl On HP-UX 11.11, pthread_create() and pthread_attr_init() are only
+ dnl defined as inline functions.
+ AC_CACHE_CHECK([whether pthread_create exists as a global function],
+ [gl_cv_func_pthread_create],
+ [saved_LIBS="$LIBS"
+ LIBS="$LIBS $LIBMULTITHREAD"
+ AC_LINK_IFELSE(
+ [AC_LANG_SOURCE(
+ [[extern
+ #ifdef __cplusplus
+ "C"
+ #endif
+ int pthread_create (void);
+ int main ()
+ {
+ return pthread_create ();
+ }
+ ]])],
+ [gl_cv_func_pthread_create=yes],
+ [gl_cv_func_pthread_create=no])
+ LIBS="$saved_LIBS"
+ ])
+ if test $gl_cv_func_pthread_create = no; then
+ REPLACE_PTHREAD_CREATE=1
+ REPLACE_PTHREAD_ATTR_INIT=1
+ AC_DEFINE([PTHREAD_CREATE_IS_INLINE], [1],
+ [Define if pthread_create is an inline function.])
+ fi
+ fi
+ fi
+])
--- /dev/null
+Description:
+Creating and controlling POSIX threads.
+
+Files:
+lib/pthread-thread.c
+m4/pthread-thread.m4
+
+Depends-on:
+pthread-h
+windows-thread [test $gl_threads_api = windows]
+
+configure.ac:
+gl_PTHREAD_THREAD
+if test $HAVE_PTHREAD_CREATE = 0 || test $REPLACE_PTHREAD_CREATE = 1; then
+ AC_LIBOBJ([pthread-thread])
+fi
+gl_PTHREAD_MODULE_INDICATOR([pthread-thread])
+
+Makefile.am:
+
+Include:
+<pthread.h>
+
+Link:
+$(LIBMULTITHREAD)
+
+License:
+LGPLv2+
+
+Maintainer:
+all