bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* ISO C 11 threads
@ 2019-06-20 10:40 Bruno Haible
  2019-06-20 10:42 ` [PATCH] ISO C 11 threads preparations Bruno Haible
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Bruno Haible @ 2019-06-20 10:40 UTC (permalink / raw)
  To: bug-gnulib

Hi,

We are now 8 years past ISO C 11, and still few systems have the ISO C 11 [1]
<threads.h>. This is a multithreading facility [2] that very much resembles
POSIX threading. The differences are:
  - Different header file: <threads.h> instead of <pthread.h>.
  - Different types: thrd_t instead of pthread_t etc.
  - Different function names (thrd_*, mtx_*, call_once, cnd_*, tss_*) instead
    pthread_*.
  - No "advanced" features, just the basic functionality.
  - Mutexes work only in a single process, not across fork()ed processes.
  - No equivalent of 'pthread_sigmask'.
  - It adds a 'thread_local' storage class, that corresponds to GCC's
    '__thread'.
  - The exit value of a thread is an 'int' instead of a 'void *'. (I think
    this is meant to ease portability to Windows [3][4].)
  - Locks/mutexes: There are only plain and recursive locks, no read-write
    locks and no spin locks. The type of a lock (plain vs. recursive and
    whether it supports waiting with a timeout) has to be specified when the
    lock is created. I think this is a recognition of the fact that the
    implementation of a recursive lock or a lock that supports waiting is
    more complex than a the implementation of a plain lock.

So far this facility is implemented in
  - glibc >= 2.29,
  - FreeBSD >= 10,
  - illumos,
  - Solaris >= 11.4 (with a bug in thrd_join),
  - AIX >= 7.1 (with terrible bugs in thrd_create and thrd_join).

To make it portably usable, I'm adding support for this facility to gnulib,
for all systems with POSIX or Windows threads.

No support for older systems, namely Minix 3.1.8, HP-UX 11.11, IRIX 5.3,
Solaris 2.4, BeOS.

Gnulib can only provide the types and functions. The 'thread_local' storage
class is something that requires compiler and linker support; we cannot
provide this portably. Applications have to use the tss_* functions instead
(just like with GCC, you need pthread_get/setspecific when '__thread' is not
available).

On native Windows, this implementation uses native Windows threads, not the
mingw pthreads emulation. This is unlike the gnulib-invented 'thread', 'lock',
'cond', 'tls' modules, which by a historical accident (the way threadlib.m4
was written) use mingw pthreads when available and not disabled through
gl_AVOID_WINPTHREAD or --enable-threads=windows.

[1] https://en.wikipedia.org/wiki/C11_(C_standard_revision)
[2] http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf
[3] https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-exitthread
[4] https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-getexitcodethread



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

end of thread, other threads:[~2019-07-04  6:49 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-20 10:40 ISO C 11 threads Bruno Haible
2019-06-20 10:42 ` [PATCH] ISO C 11 threads preparations Bruno Haible
2019-06-20 10:45 ` [PATCH] ISO C 11 threads implementation Bruno Haible
2019-06-20 16:34   ` Paul Eggert
2019-06-20 17:50     ` Bruno Haible
2019-07-01  2:46       ` Bruno Haible
2019-07-04  6:49         ` Paul Eggert
2019-06-21  9:22   ` Bruno Haible
2019-06-21  9:45   ` Bruno Haible
2019-06-20 17:19 ` ISO C 11 threads Bruno Haible
2019-06-21  1:12 ` 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).