<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 858: Wording for Minimal Support for Garbage Collection</title>
<meta property="og:title" content="Issue 858: Wording for Minimal Support for Garbage Collection">
<meta property="og:description" content="C++ library issue. Status: CD1">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue858.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#CD1">CD1</a> status.</em></p>
<h3 id="858"><a href="lwg-defects.html#858">858</a>. Wording for Minimal Support for Garbage Collection</h3>
<p><b>Section:</b> 99 [util.dynamic.safety] <b>Status:</b> <a href="lwg-active.html#CD1">CD1</a>
 <b>Submitter:</b> Pete Becker  <b>Opened:</b> 2008-06-21 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#util.dynamic.safety">issues</a> in [util.dynamic.safety].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#CD1">CD1</a> status.</p>
<p><b>Discussion:</b></p>
<p>
The first sentence of the Effects clause for <code>undeclare_reachable</code> seems
to be missing some words. I can't parse
</p>
<blockquote><p>
... for all non-null <code>p</code> referencing the argument is no longer declared reachable...
</p></blockquote>
<p>
I take it the intent is that <code>undeclare_reachable</code> should be called only
when there has been a corresponding call to <code>declare_reachable</code>. In
particular, although the wording seems to allow it, I assume that code
shouldn't call <code>declare_reachable</code> once then call <code>undeclare_reachable</code>
twice.
</p>
<p>
I don't know what "shall be live" in the Requires clause means.
</p>
<p>
In the final Note for <code>undeclare_reachable</code>, what does "cannot be
deallocated" mean? Is this different from "will not be able to collect"?
</p>

<p>
For the wording on nesting of <code>declare_reachable</code> and
<code>undeclare_reachable</code>, the words for locking and unlocking recursive
mutexes probably are a good model.
</p>

<p><i>[
San Francisco:
]</i></p>


<blockquote>
<p>
Nick: what does "shall be live" mean?
</p>
<p>
Hans: I can provide an appropriate cross-reference to the Project Editor
to clarify the intent.
</p>
</blockquote>


<p id="res-858"><b>Proposed resolution:</b></p>
<p>
In 99 [util.dynamic.safety]
(<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2670.htm">N2670</a>,
Minimal Support for Garbage Collection)
</p>
<p>
Add at the beginning, before paragraph 39
</p>

<blockquote><p>
A complete object is <i>declared reachable</i> while the number of calls
to <code>declare_reachable</code> with an argument referencing the object exceeds the
number of <code>undeclare_reachable</code> calls with pointers to the same complete
object.
</p></blockquote>

<p>
Change paragraph 42 (Requires clause for <code>undeclare_reachable</code>)
</p>

<blockquote><p>
If <code>p</code> is not null, <del><code>declare_reachable(p)</code> was previously called</del>
<ins>the complete object referenced by <code>p</code> shall have
been previously declared reachable</ins>, and shall
be live <ins>(6.8.4 <a href="https://wg21.link/basic.life">[basic.life]</a>)</ins> from the time of the call until the last <code>undeclare_reachable(p)</code>
call on the object.
</p></blockquote>

<p>
Change the first sentence in paragraph 44 (Effects clause for
<code>undeclare_reachable</code>):
</p>

<blockquote><p>
<i>Effects:</i> 
<del>Once the number of calls to
<code>undeclare_reachable(p)</code> equals the number of calls to
<code>declare_reachable(p)</code>
for all non-null <code>p</code> referencing
the argument is no longer declared reachable.  When this happens,
pointers to the object referenced by p may not be subsequently
dereferenced.</del>
<ins>
After a call to <code>undeclare_reachable(p)</code>, if <code>p</code> is not null and the object <code>q</code>
referenced by <code>p</code> is no longer declared reachable, then
dereferencing any pointer to <code>q</code> that is not safely derived
results in undefined behavior.
</ins> ...
</p></blockquote>

<p>
Change the final note:
</p>
<p>
[<i>Note:</i> It is expected that calls to <code>declare_reachable(p)</code>
will consume a small amount of memory<ins>, in addition to that occupied
by the referenced object, </ins> until the matching call to
<code>undeclare_reachable(p)</code> is encountered. <del>In addition, the
referenced object cannot be deallocated during this period, and garbage
collecting implementations will not be able to collect the object while
it is declared reachable.</del> Long running programs should arrange
that calls <ins>for short-lived objects</ins> are matched. <i>--end
note</i>]
</p>






</body>
</html>
