]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/fortran/doc/gfortran/compiler-characteristics/thread-safety-of-the-runtime-library.rst
sphinx: add missing trailing newline
[thirdparty/gcc.git] / gcc / fortran / doc / gfortran / compiler-characteristics / thread-safety-of-the-runtime-library.rst
CommitLineData
c63539ff
ML
1..
2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
5
6.. index:: thread-safety, threads
7
8.. _thread-safety-of-the-runtime-library:
9
10Thread-safety of the runtime library
11************************************
12
13GNU Fortran can be used in programs with multiple threads, e.g. by
14using OpenMP, by calling OS thread handling functions via the
15``ISO_C_BINDING`` facility, or by GNU Fortran compiled library code
16being called from a multi-threaded program.
17
18The GNU Fortran runtime library, (``libgfortran``), supports being
19called concurrently from multiple threads with the following
20exceptions.
21
22During library initialization, the C ``getenv`` function is used,
23which need not be thread-safe. Similarly, the ``getenv``
24function is used to implement the ``GET_ENVIRONMENT_VARIABLE`` and
25``GETENV`` intrinsics. It is the responsibility of the user to
26ensure that the environment is not being updated concurrently when any
27of these actions are taking place.
28
29The ``EXECUTE_COMMAND_LINE`` and ``SYSTEM`` intrinsics are
30implemented with the ``system`` function, which need not be
31thread-safe. It is the responsibility of the user to ensure that
32``system`` is not called concurrently.
33
34For platforms not supporting thread-safe POSIX functions, further
35functionality might not be thread-safe. For details, please consult
36the documentation for your operating system.
37
38The GNU Fortran runtime library uses various C library functions that
39depend on the locale, such as ``strtod`` and ``snprintf``. In
40order to work correctly in locale-aware programs that set the locale
41using ``setlocale``, the locale is reset to the default 'C'
42locale while executing a formatted ``READ`` or ``WRITE``
43statement. On targets supporting the POSIX 2008 per-thread locale
44functions (e.g. ``newlocale``, ``uselocale``,
45``freelocale``), these are used and thus the global locale set
46using ``setlocale`` or the per-thread locales in other threads are
47not affected. However, on targets lacking this functionality, the
48global LC_NUMERIC locale is set to 'C' during the formatted I/O.
49Thus, on such targets it's not safe to call ``setlocale``
50concurrently from another thread while a Fortran formatted I/O
51operation is in progress. Also, other threads doing something
52dependent on the LC_NUMERIC locale might not work correctly if a
3ed1b4ce 53formatted I/O operation is in progress in another thread.