Thread_002dsafety-of-the-runtime-library.html 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1999-2017 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <title>The GNU Fortran Compiler: Thread-safety of the runtime library</title>
  20. <meta name="description" content="The GNU Fortran Compiler: Thread-safety of the runtime library">
  21. <meta name="keywords" content="The GNU Fortran Compiler: Thread-safety of the runtime library">
  22. <meta name="resource-type" content="document">
  23. <meta name="distribution" content="global">
  24. <meta name="Generator" content="makeinfo">
  25. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="Compiler-Characteristics.html#Compiler-Characteristics" rel="up" title="Compiler Characteristics">
  30. <link href="Data-consistency-and-durability.html#Data-consistency-and-durability" rel="next" title="Data consistency and durability">
  31. <link href="Internal-representation-of-LOGICAL-variables.html#Internal-representation-of-LOGICAL-variables" rel="prev" title="Internal representation of LOGICAL variables">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.smallquotation {font-size: smaller}
  36. div.display {margin-left: 3.2em}
  37. div.example {margin-left: 3.2em}
  38. div.indentedblock {margin-left: 3.2em}
  39. div.lisp {margin-left: 3.2em}
  40. div.smalldisplay {margin-left: 3.2em}
  41. div.smallexample {margin-left: 3.2em}
  42. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style:oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nocodebreak {white-space:nowrap}
  54. span.nolinebreak {white-space:nowrap}
  55. span.roman {font-family:serif; font-weight:normal}
  56. span.sansserif {font-family:sans-serif; font-weight:normal}
  57. ul.no-bullet {list-style: none}
  58. -->
  59. </style>
  60. </head>
  61. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  62. <a name="Thread_002dsafety-of-the-runtime-library"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Data-consistency-and-durability.html#Data-consistency-and-durability" accesskey="n" rel="next">Data consistency and durability</a>, Previous: <a href="Internal-representation-of-LOGICAL-variables.html#Internal-representation-of-LOGICAL-variables" accesskey="p" rel="prev">Internal representation of LOGICAL variables</a>, Up: <a href="Compiler-Characteristics.html#Compiler-Characteristics" accesskey="u" rel="up">Compiler Characteristics</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  66. </div>
  67. <hr>
  68. <a name="Thread_002dsafety-of-the-runtime-library-1"></a>
  69. <h3 class="section">5.3 Thread-safety of the runtime library</h3>
  70. <a name="index-thread_002dsafety_002c-threads"></a>
  71. <p>GNU Fortran can be used in programs with multiple threads, e.g. by
  72. using OpenMP, by calling OS thread handling functions via the
  73. <code>ISO_C_BINDING</code> facility, or by GNU Fortran compiled library code
  74. being called from a multi-threaded program.
  75. </p>
  76. <p>The GNU Fortran runtime library, (<code>libgfortran</code>), supports being
  77. called concurrently from multiple threads with the following
  78. exceptions.
  79. </p>
  80. <p>During library initialization, the C <code>getenv</code> function is used,
  81. which need not be thread-safe. Similarly, the <code>getenv</code>
  82. function is used to implement the <code>GET_ENVIRONMENT_VARIABLE</code> and
  83. <code>GETENV</code> intrinsics. It is the responsibility of the user to
  84. ensure that the environment is not being updated concurrently when any
  85. of these actions are taking place.
  86. </p>
  87. <p>The <code>EXECUTE_COMMAND_LINE</code> and <code>SYSTEM</code> intrinsics are
  88. implemented with the <code>system</code> function, which need not be
  89. thread-safe. It is the responsibility of the user to ensure that
  90. <code>system</code> is not called concurrently.
  91. </p>
  92. <p>For platforms not supporting thread-safe POSIX functions, further
  93. functionality might not be thread-safe. For details, please consult
  94. the documentation for your operating system.
  95. </p>
  96. <p>The GNU Fortran runtime library uses various C library functions that
  97. depend on the locale, such as <code>strtod</code> and <code>snprintf</code>. In
  98. order to work correctly in locale-aware programs that set the locale
  99. using <code>setlocale</code>, the locale is reset to the default &ldquo;C&rdquo;
  100. locale while executing a formatted <code>READ</code> or <code>WRITE</code>
  101. statement. On targets supporting the POSIX 2008 per-thread locale
  102. functions (e.g. <code>newlocale</code>, <code>uselocale</code>,
  103. <code>freelocale</code>), these are used and thus the global locale set
  104. using <code>setlocale</code> or the per-thread locales in other threads are
  105. not affected. However, on targets lacking this functionality, the
  106. global LC_NUMERIC locale is set to &ldquo;C&rdquo; during the formatted I/O.
  107. Thus, on such targets it&rsquo;s not safe to call <code>setlocale</code>
  108. concurrently from another thread while a Fortran formatted I/O
  109. operation is in progress. Also, other threads doing something
  110. dependent on the LC_NUMERIC locale might not work correctly if a
  111. formatted I/O operation is in progress in another thread.
  112. </p>
  113. <hr>
  114. <div class="header">
  115. <p>
  116. Next: <a href="Data-consistency-and-durability.html#Data-consistency-and-durability" accesskey="n" rel="next">Data consistency and durability</a>, Previous: <a href="Internal-representation-of-LOGICAL-variables.html#Internal-representation-of-LOGICAL-variables" accesskey="p" rel="prev">Internal representation of LOGICAL variables</a>, Up: <a href="Compiler-Characteristics.html#Compiler-Characteristics" accesskey="u" rel="up">Compiler Characteristics</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  117. </div>
  118. </body>
  119. </html>