bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

New options --enable-threads=isoc and --enable-threads=isoc+posix


From: Bruno Haible
Subject: New options --enable-threads=isoc and --enable-threads=isoc+posix
Date: Wed, 27 Nov 2019 10:24:53 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-166-generic; KDE/5.18.0; x86_64; ; )

This patch adds support for new alternatives
  --enable-threads=isoc
  --enable-threads=isoc+posix
to the modules lock, cond, tls, yield, thread, which so far only supported
  --enable-threads=posix
  --enable-threads=windows

The purpose is to be future-proof: When new OSes arise that support the ISO C
threads API instead of or with better trade-offs than the POSIX threads API,
the modules can use it.

I've tested these options on
  - recent glibc systems (with CC="gcc -lpthread"),
  - Solaris 11 OpenIndiana,
  - Solaris 11.4,
  - AIX 7.1.

Currently, these options are not practically useful because
1) The ISO C threads API has three disadvantages compared to the POSIX threads
   API:
     - No support for the atfork operation,
     - Locks and condition variables cannot be initialized through a static
       initializer, but require runtime initialization instead,
     - A thread's exit value is merely an 'int', not a 'void *'.
2) Programs that use it still need to be linked with -lpthread on some
   platforms:
     - On glibc systems, linking with -lpthread is required in order to
       create threads other than the initial thread.
     - On AIX, --enable-threads=isoc saves you from passing -pthread to
       the compiler when linking, but 'ldd' shows that the resulting
       executables are still linked against libpthread (through some
       linker magic that detects that use of thrd_* functions).


2019-11-27  Bruno Haible  <address@hidden>

        New options --enable-threads=isoc and --enable-threads=isoc+posix.
        * m4/threadlib.m4 (gl_THREADLIB_EARLY_BODY): Accept the options
        --enable-threads=isoc and --enable-threads=isoc+posix.
        (gl_THREADLIB_BODY): Test whether the ISO C threads API is available.
        When both the ISO C and the POSIX threads API are available, choose
        USE_ISOC_AND_POSIX_THREADS instead of USE_POSIX_THREADS if
        --enable-threads=isoc+posix was specified. When only the ISO C threads
        API is available and --enable-threads=iso was specified, choose
        USE_ISOC_THREADS.
        * lib/glthread/lock.h: Add new code for USE_ISOC_THREADS ||
        USE_ISOC_AND_POSIX_THREADS.
        * lib/glthread/lock.c: Likewise.
        * lib/glthread/cond.h: Likewise.
        * lib/glthread/cond.c: Likewise.
        * lib/glthread/tls.h: Likewise.
        * lib/glthread/tls.c: Likewise.
        * lib/glthread/yield.h: Likewise.
        * lib/glthread/thread.h: Add new code for USE_ISOC_THREADS. Treat
        USE_ISOC_AND_POSIX_THREADS like USE_POSIX_THREADS.
        * lib/glthread/thread.c: Likewise.
        * lib/glthread/threadlib.c: Likewise.
        * tests/test-lock.c: Save and restore the values of USE_ISOC_THREADS and
        USE_ISOC_AND_POSIX_THREADS.
        * tests/test-cond.c: Consider USE_ISOC_THREADS and
        USE_ISOC_AND_POSIX_THREADS.
        * tests/test-tls.c: Likewise.
        * tests/test-thread_create.c (main): Likewise.
        * tests/test-pthread-cond.c: Likewise.
        * tests/test-pthread-mutex.c: Likewise.
        * tests/test-pthread-once2.c: Likewise.
        * tests/test-pthread-rwlock.c: Likewise.
        * tests/test-pthread-tss.c: Likewise.
        * tests/test-pthread_sigmask2.c: Treat USE_ISOC_AND_POSIX_THREADS like
        USE_POSIX_THREADS.

Attachment: 0001-New-options-enable-threads-isoc-and-enable-threads-i.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]