bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* buy into mingw winpthreads?
@ 2019-05-18 13:07 Bruno Haible
  2019-05-18 20:23 ` LRN
  2019-05-18 22:42 ` Bruno Haible
  0 siblings, 2 replies; 3+ messages in thread
From: Bruno Haible @ 2019-05-18 13:07 UTC (permalink / raw)
  To: bug-gnulib; +Cc: Miguel Ángel Arruga Vivas, Michele Locati

Hi,

What should be the default threading API used by the module 'threadlib'
(and thus also 'lock', 'rwlock', 'cond', etc.) on mingw. There are two choices:

--enable-threads=windows
  does not need non-Microsoft DLLs.

--enable-threads=posix
  links against winpthreads.dll.
  (Whereas Ross Johnson's pthreads-win32 [1] is apparently no longer maintained for
  7 years, therefore no viable option.)
  
Arguments I can see in favour of --enable-threads=windows:

  * The gnulib threads code (lib/glthread/) for Windows is much smaller than the
    one in mingw's winpthreads, thus contains likely fewer bugs.

  * The gnulib threads code is portable across architectures; no assembly-language
    code.

  * It makes me nervous to see that, 5 years after winpthreads was declared no
    longer experimental (in 2013), we still see fixes of race conditions and dirty hacks:
      2019-04-26  winpthreads/cond.c: Remove waits for `sema_b` from wait functions.
      2019-04-26  winpthreads/cond.c: Only update `waiters_count_` with `waiters_count_lock_` locked.
      2017-03-10  winpthreads/src/thread.c: Force aligning ESP on 16-byte boundaries on x86.
      2016-11-24  winpthreads mem leak fixed

  * One less DLL dependency.

Arguments I can see in favour of --enable-threads=posix:

  * The mingw platform is moving away from a "minimal" layer on top of
    Windows towards an ISO C + POSIX layer. There is no point in working
    against this evolution.

Opinions?

Bruno

[1] https://sourceware.org/pthreads-win32/



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: buy into mingw winpthreads?
  2019-05-18 13:07 buy into mingw winpthreads? Bruno Haible
@ 2019-05-18 20:23 ` LRN
  2019-05-18 22:42 ` Bruno Haible
  1 sibling, 0 replies; 3+ messages in thread
From: LRN @ 2019-05-18 20:23 UTC (permalink / raw)
  To: bug-gnulib


[-- Attachment #1.1: Type: text/plain, Size: 713 bytes --]

On 18.05.2019 16:07, Bruno Haible wrote:
> Opinions?

I don't use gnulib much, but as far as threads are concerned:

Applications can use Windows threading APIs, if they need limited threading
support and know exactly what they want, and if the developers know how to use
Windows API correctly.

Portable libraries and frameworks are better with a full pthreads compatibility
library (unless the threading interface that they provide to other applications
does not resemble pthreads *at all*). Because if they try to implement a
POSIX-resembling threading-related API based on Windows thread API, they might
just end up re-implementing their own version of winpthreads, which is a waste
of time.


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: buy into mingw winpthreads?
  2019-05-18 13:07 buy into mingw winpthreads? Bruno Haible
  2019-05-18 20:23 ` LRN
@ 2019-05-18 22:42 ` Bruno Haible
  1 sibling, 0 replies; 3+ messages in thread
From: Bruno Haible @ 2019-05-18 22:42 UTC (permalink / raw)
  To: bug-gnulib; +Cc: Miguel Ángel Arruga Vivas, Michele Locati

While it is hard to make a decision for all packages altogether, specific
packages should have an easy way to set their preferred default.


2019-05-18  Bruno Haible  <bruno@clisp.org>

	threadlib: Provide an easy way to avoid mingw's winpthreads library.
	* m4/threadlib.m4 (gl_AVOID_WINPTHREAD): New macro.
	(gl_THREADLIB_EARLY_BODY): Recognize when it was invoked, and set
	gl_use_threads accordingly.

diff --git a/m4/threadlib.m4 b/m4/threadlib.m4
index bfc3bac..b4401f8 100644
--- a/m4/threadlib.m4
+++ b/m4/threadlib.m4
@@ -1,4 +1,4 @@
-# threadlib.m4 serial 16
+# threadlib.m4 serial 17
 dnl Copyright (C) 2005-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,
@@ -50,6 +50,7 @@ AC_DEFUN([gl_THREADLIB_EARLY_BODY],
   m4_ifdef([gl_THREADLIB_DEFAULT_NO],
     [m4_divert_text([DEFAULTS], [gl_use_threads_default=no])],
     [m4_divert_text([DEFAULTS], [gl_use_threads_default=])])
+  m4_divert_text([DEFAULTS], [gl_use_winpthreads_default=])
   AC_ARG_ENABLE([threads],
 AC_HELP_STRING([--enable-threads={posix|solaris|pth|windows}], [specify multithreading API])m4_ifdef([gl_THREADLIB_DEFAULT_NO], [], [
 AC_HELP_STRING([--disable-threads], [build without multithread safety])]),
@@ -62,16 +63,24 @@ changequote(,)dnl
          dnl Disable multithreading by default on OSF/1, because it interferes
          dnl with fork()/exec(): When msgexec is linked with -lpthread, its
          dnl child process gets an endless segmentation fault inside execvp().
+         osf*) gl_use_threads=no ;;
          dnl Disable multithreading by default on Cygwin 1.5.x, because it has
          dnl bugs that lead to endless loops or crashes. See
          dnl <https://cygwin.com/ml/cygwin/2009-08/msg00283.html>.
-         osf*) gl_use_threads=no ;;
          cygwin*)
                case `uname -r` in
                  1.[0-5].*) gl_use_threads=no ;;
                  *)         gl_use_threads=yes ;;
                esac
                ;;
+         dnl Obey gl_AVOID_WINPTHREAD on mingw.
+         mingw*)
+               case "$gl_use_winpthreads_default" in
+                 yes) gl_use_threads=posix ;;
+                 no)  gl_use_threads=windows ;;
+                 *)   gl_use_threads=yes ;;
+               esac
+               ;;
          *)    gl_use_threads=yes ;;
        esac
 changequote([,])dnl
@@ -337,6 +346,18 @@ AC_DEFUN([gl_DISABLE_THREADS], [
 ])
 
 
+dnl gl_AVOID_WINPTHREAD
+dnl -------------------
+dnl Sets the gl_THREADLIB default so that on mingw, a dependency to the
+dnl libwinpthread DLL (mingw-w64 winpthreads library) is avoided.
+dnl The user can still override it at installation time, by using the
+dnl configure option '--enable-threads'.
+
+AC_DEFUN([gl_AVOID_WINPTHREAD], [
+  m4_divert_text([INIT_PREPARE], [gl_use_winpthreads_default=no])
+])
+
+
 dnl Survey of platforms:
 dnl
 dnl Platform           Available  Compiler    Supports   test-lock



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-05-18 22:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-18 13:07 buy into mingw winpthreads? Bruno Haible
2019-05-18 20:23 ` LRN
2019-05-18 22:42 ` Bruno Haible

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).