<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2653: [filesys.ts] [PDTS] directory_entry multithreading concerns</title>
<meta property="og:title" content="Issue 2653: [filesys.ts] [PDTS] directory_entry multithreading concerns">
<meta property="og:description" content="C++ library issue. Status: TS">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2653.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#TS">TS</a> status.</em></p>
<h3 id="2653"><a href="lwg-defects.html#2653">2653</a>. [filesys.ts] [PDTS] <code>directory_entry</code> multithreading concerns</h3>
<p><b>Section:</b> 12 [filesys.ts::class.directory_entry] <b>Status:</b> <a href="lwg-active.html#TS">TS</a>
 <b>Submitter:</b> Stephan T. Lavavej <b>Opened:</b> 2014-02-03 <b>Last modified:</b> 2017-07-30</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#filesys.ts::class.directory_entry">issues</a> in [filesys.ts::class.directory_entry].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#TS">TS</a> status.</p>
<p><b>Discussion:</b></p>
<p><b>Addresses: filesys.ts</b></p>
<p>12 [class.directory_entry] depicts <code>directory_entry</code> as having <code>mutable m_status</code> and
<code>m_symlink_status</code> data members.  This is problematic because of C++11's multithreading
guarantees, which say that <code>const</code> member functions are simultaneously callable.
As a result, <code>mutable</code> data members must be protected with synchronization, which was
probably not considered during this design.  The complexity and expense may be acceptable
in <code>directory_entry</code> (since it can save filesystem queries, apparently) but it would be
very very nice to have a note about this.</p>

  <p><i>[2014-02-13 LWG/SG-3 discussed in Issaquah: Beman and STL will work together to better
  understand the concerns, and to formulate a solution. This is not a blocking issue for
  finishing the TS, but is a blocking issue for merging into the IS]</i></p>

  
  <p><i>[2014-04-17 Beman provides proposed wording]</i></p>

  <p><i>[2014-06-19 Rapperswil LWG decides to remove mutable private members. Beman provides wording.]</i></p>




<p id="res-2653"><b>Proposed resolution:</b></p>

  <p/>
  <i>Change 12 [class.directory_entry] as indicated:</i>

  <pre>
    namespace std { namespace experimental { namespace filesystem { inline namespace v1 {

    class directory_entry
    {
    public:

    // constructors and destructor
    directory_entry() = default;
    directory_entry(const directory_entry&amp;) = default;
    directory_entry(directory_entry&amp;&amp;) noexcept = default;
    <ins>explicit directory_entry(const path&amp; p);</ins>
    <del>explicit directory_entry(const path&amp; p, file_status st=file_status(),</del>
      <del>file_status symlink_st=file_status());</del>
    ~directory_entry();

    // modifiers
    directory_entry&amp; operator=(const directory_entry&amp;) = default;
    directory_entry&amp; operator=(directory_entry&amp;&amp;) noexcept = default;
    <ins>void assign(const path&amp; p);</ins>
    <del>void assign(const path&amp; p, file_status st=file_status()</del>,
      <del>file_status symlink_st=file_status()</del>);
    <ins>void replace_filename(const path&amp; p);</ins>
    <del>void replace_filename(const path&amp; p, file_status st=file_status()</del>,
      <del>file_status symlink_st=file_status()</del>);

    // observers
    const path&amp;  path() const noexcept;
    file_status  status() const;
    file_status  status(error_code&amp; ec) const noexcept;
    file_status  symlink_status() const;
    file_status  symlink_status(error_code&amp; ec) const noexcept;

    bool operator&lt; (const directory_entry&amp; rhs) const noexcept;
    bool operator==(const directory_entry&amp; rhs) const noexcept;
    bool operator!=(const directory_entry&amp; rhs) const noexcept;
    bool operator&lt;=(const directory_entry&amp; rhs) const noexcept;
    bool operator&gt; (const directory_entry&amp; rhs) const noexcept;
    bool operator&gt;=(const directory_entry&amp; rhs) const noexcept;
    private:
    path                 m_path;           // for exposition only
    <del>mutable file_status  m_status;         // for exposition only; stat()-like</del>
    <del>mutable file_status  m_symlink_status; // for exposition only; lstat()-like</del>
    };

    } } } }  // namespaces std::experimental::filesystem::v1
  </pre>
  <p>
    A <code>directory_entry</code> object stores a <code>path</code> object<del>,</del>
    <del>a <code>file_status</code> object for non-symbolic link status, and a <code>file_status</code> object for symbolic link status</del>.
    <del>
      The <code>file_status</code> objects act as value caches.
    </del>
  </p>
  <blockquote>
    <p>
      <del>
        [<i>Note:</i> Because <code>status()</code>on a pathname may be a relatively expensive operation,
        some operating systems provide status information as a byproduct of directory
        iteration. Caching such status information can result in significant time savings. Cached and
        non-cached results may differ in the presence of file system races. <i>&mdash;end note</i>]
      </del>
    </p>
  </blockquote>
  <h3>
    12.1  <a name="directory_entry-constructors">
      <code>directory_entry</code> constructors
    </a>
    [directory_entry.cons]
  </h3>

   <p>
      <i>
        <span style="background-color: #C0C0C0">
          Add the description of this
          constructor in its entirety:
        </span>
      </i>
    </p>
   <pre>explicit directory_entry(const path&amp; p);</pre>
  <blockquote>
    <p/><i>Effects: </i>Constructs an object of type <code>directory_entry</code>
    
    <p>
      <i>Postcondition:</i>
      <code>path() == p</code>.
    </p>

  </blockquote>
  <pre><del>explicit directory_entry(const path&amp; p, file_status st=file_status()</del>,
    <del>file_status symlink_st=file_status()</del>);</pre>
  <blockquote>
    <p>
      <span style="background-color: #C0C0C0">
        <i>Strike the description</i>
      </span>
    </p>

    
  </blockquote>
  <h3>
    12.2  <a name="directory_entry-modifiers">
      <code>directory_entry</code> modifiers
    </a>
    [directory_entry.mods]
  </h3>

  <p>
    <i>
      <span style="background-color: #C0C0C0">
        Add the description of this
        function in its entirety:
      </span>
    </i>
  </p>
  <pre>void assign(const path&amp; p);</pre>
  <blockquote>
    <p>
      <i>Postcondition:</i>
      <code>path() == p</code>.
    </p>
 
  </blockquote>
  <pre><del>void assign(const path&amp; p, file_status st=file_status()</del>,
  <del>file_status symlink_st=file_status());</del></pre>
  <blockquote>
    <p>
      <span style="background-color: #C0C0C0">
        <i>Strike the description</i>
      </span>
    </p>
  </blockquote>

  <p>
    <i>
      <span style="background-color: #C0C0C0">
        Add the description of this
        function in its entirety:
      </span>
    </i>
  </p>
  <pre>void replace_filename(const path&amp; p);</pre>
  <blockquote>
    <p>
      <i>Postcondition:</i> <code>path() == x.parent_path() / p</code>
      where <code>x</code> is the value of <code>path()</code>
      before the function is called.
    </p>
  </blockquote>
  <pre><del>void replace_filename(const path&amp; p, file_status st=file_status()</del>,
  <del>file_status symlink_st=file_status());</del></pre>
  <blockquote>
    <p>
      <span style="background-color: #C0C0C0">
        <i>Strike the description</i>
      </span>
    </p>
  </blockquote>
  <h3>
    12.3  <a name="directory_entry-observers">
      <code>directory_entry</code> observers
    </a>
    [directory_entry.obs]
  </h3>
  <pre>const path&amp; path() const noexcept;</pre>
  <blockquote>
    <p>
      <i>Returns:</i>
      <code>m_path</code>
    </p>
  </blockquote>
  <pre>file_status status() const;
file_status status(error_code&amp; ec) const noexcept;</pre>
  <blockquote>
    <p>
      <del><i>Effects:</i> As if,</del>
    </p>
    <blockquote>
      <pre><del>if (!status_known(m_status))
{
  if (status_known(m_symlink_status) &amp;&amp; !is_symlink(m_symlink_status))
    { m_status = m_symlink_status; }
  else { m_status = status(m_path<i>[, ec]</i>); }
}</del></pre>
    </blockquote>
    <p>
      <i>Returns:</i>
      <code>
        <del>m_status</del>
        <ins>status(path()<i>[, ec]</i>)</ins>
      </code>.
    </p>

    <p>
      <i>Throws:</i> As specified in Error reporting (7).
    </p>

  </blockquote>
  <pre>file_status  symlink_status() const;
file_status  symlink_status(error_code&amp; ec) const noexcept;</pre>
  <blockquote>
    <p>
      <del><i>Effects:</i> As if,</del>
    </p>
    <blockquote>
      <pre><del>
        if (!status_known(m_symlink_status))
        {
        m_symlink_status = symlink_status(m_path<i>[, ec]</i>);
        }</del></pre>
    </blockquote>
    <p>
      <i>Returns:</i>
      <code>
        <del>m_symlink_status</del>
        <ins>symlink_status(path()<i>[, ec]</i>)</ins>
      </code>.
    </p>

    <p>
      <i>Throws:</i> As specified in Error reporting (7).
    </p>

  </blockquote>
  <pre>bool operator==(const directory_entry&amp; rhs) const noexcept;</pre>
  <blockquote>
    <p>
      <i>Returns:</i> <code>m_path == rhs.m_path</code>.
    </p>
    <p>
      <del>[<i>Note:</i> Status members do not participate in determining
      equality. — end note]</del>
    </p>
  </blockquote>
  <pre>bool operator!=(const directory_entry&amp; rhs) const noexcept;</pre>
  <blockquote>
    <p>
      <i>Returns:</i> <code>m_path != rhs.m_path</code>.
    </p>
  </blockquote>
  <pre>bool operator&lt; (const directory_entry&amp; rhs) const noexcept;</pre>
  <blockquote>
    <p>
      <i>Returns:</i> <code>m_path &lt; rhs.m_path</code>.
    </p>
  </blockquote>
  <pre>bool operator&lt;=(const directory_entry&amp; rhs) const noexcept;</pre>
  <blockquote>
    <p>
      <i>Returns:</i> <code>m_path &lt;= rhs.m_path</code>.
    </p>
  </blockquote>
  <pre>bool operator&gt; (const directory_entry&amp; rhs) const noexcept;</pre>
  <blockquote>
    <p>
      <i>Returns:</i> <code>m_path &gt; rhs.m_path</code>.
    </p>
  </blockquote>
  <pre>bool operator&gt;=(const directory_entry&amp; rhs) const noexcept;</pre>
  <blockquote>
    <p>
      <i>Returns:</i> <code>m_path &gt;= rhs.m_path</code>.
    </p>
  </blockquote>









</body>
</html>
