Data-consistency-and-durability.html 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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: Data consistency and durability</title>
  20. <meta name="description" content="The GNU Fortran Compiler: Data consistency and durability">
  21. <meta name="keywords" content="The GNU Fortran Compiler: Data consistency and durability">
  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="Files-opened-without-an-explicit-ACTION_003d-specifier.html#Files-opened-without-an-explicit-ACTION_003d-specifier" rel="next" title="Files opened without an explicit ACTION= specifier">
  31. <link href="Thread_002dsafety-of-the-runtime-library.html#Thread_002dsafety-of-the-runtime-library" rel="prev" title="Thread-safety of the runtime library">
  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="Data-consistency-and-durability"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Files-opened-without-an-explicit-ACTION_003d-specifier.html#Files-opened-without-an-explicit-ACTION_003d-specifier" accesskey="n" rel="next">Files opened without an explicit ACTION= specifier</a>, Previous: <a href="Thread_002dsafety-of-the-runtime-library.html#Thread_002dsafety-of-the-runtime-library" accesskey="p" rel="prev">Thread-safety of the runtime library</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="Data-consistency-and-durability-1"></a>
  69. <h3 class="section">5.4 Data consistency and durability</h3>
  70. <a name="index-consistency_002c-durability"></a>
  71. <p>This section contains a brief overview of data and metadata
  72. consistency and durability issues when doing I/O.
  73. </p>
  74. <p>With respect to durability, GNU Fortran makes no effort to ensure that
  75. data is committed to stable storage. If this is required, the GNU
  76. Fortran programmer can use the intrinsic <code>FNUM</code> to retrieve the
  77. low level file descriptor corresponding to an open Fortran unit. Then,
  78. using e.g. the <code>ISO_C_BINDING</code> feature, one can call the
  79. underlying system call to flush dirty data to stable storage, such as
  80. <code>fsync</code> on POSIX, <code>_commit</code> on MingW, or <code>fcntl(fd,
  81. F_FULLSYNC, 0)</code> on Mac OS X. The following example shows how to call
  82. fsync:
  83. </p>
  84. <div class="smallexample">
  85. <pre class="smallexample"> ! Declare the interface for POSIX fsync function
  86. interface
  87. function fsync (fd) bind(c,name=&quot;fsync&quot;)
  88. use iso_c_binding, only: c_int
  89. integer(c_int), value :: fd
  90. integer(c_int) :: fsync
  91. end function fsync
  92. end interface
  93. ! Variable declaration
  94. integer :: ret
  95. ! Opening unit 10
  96. open (10,file=&quot;foo&quot;)
  97. ! ...
  98. ! Perform I/O on unit 10
  99. ! ...
  100. ! Flush and sync
  101. flush(10)
  102. ret = fsync(fnum(10))
  103. ! Handle possible error
  104. if (ret /= 0) stop &quot;Error calling FSYNC&quot;
  105. </pre></div>
  106. <p>With respect to consistency, for regular files GNU Fortran uses
  107. buffered I/O in order to improve performance. This buffer is flushed
  108. automatically when full and in some other situations, e.g. when
  109. closing a unit. It can also be explicitly flushed with the
  110. <code>FLUSH</code> statement. Also, the buffering can be turned off with the
  111. <code>GFORTRAN_UNBUFFERED_ALL</code> and
  112. <code>GFORTRAN_UNBUFFERED_PRECONNECTED</code> environment variables. Special
  113. files, such as terminals and pipes, are always unbuffered. Sometimes,
  114. however, further things may need to be done in order to allow other
  115. processes to see data that GNU Fortran has written, as follows.
  116. </p>
  117. <p>The Windows platform supports a relaxed metadata consistency model,
  118. where file metadata is written to the directory lazily. This means
  119. that, for instance, the <code>dir</code> command can show a stale size for a
  120. file. One can force a directory metadata update by closing the unit,
  121. or by calling <code>_commit</code> on the file descriptor. Note, though,
  122. that <code>_commit</code> will force all dirty data to stable storage, which
  123. is often a very slow operation.
  124. </p>
  125. <p>The Network File System (NFS) implements a relaxed consistency model
  126. called open-to-close consistency. Closing a file forces dirty data and
  127. metadata to be flushed to the server, and opening a file forces the
  128. client to contact the server in order to revalidate cached
  129. data. <code>fsync</code> will also force a flush of dirty data and metadata
  130. to the server. Similar to <code>open</code> and <code>close</code>, acquiring and
  131. releasing <code>fcntl</code> file locks, if the server supports them, will
  132. also force cache validation and flushing dirty data and metadata.
  133. </p>
  134. <hr>
  135. <div class="header">
  136. <p>
  137. Next: <a href="Files-opened-without-an-explicit-ACTION_003d-specifier.html#Files-opened-without-an-explicit-ACTION_003d-specifier" accesskey="n" rel="next">Files opened without an explicit ACTION= specifier</a>, Previous: <a href="Thread_002dsafety-of-the-runtime-library.html#Thread_002dsafety-of-the-runtime-library" accesskey="p" rel="prev">Thread-safety of the runtime library</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>
  138. </div>
  139. </body>
  140. </html>