<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>N3269: shared_future(future&lt;R&gt;&amp;&amp;) should be allowed to throw</title>
  <style type="text/css">
del, del * { background-color: #FF6666 ; color: #0000CC }
ins, ins * { background-color: #99FFCC; color:  #0000CC }
  </style>
</head>

<body>
  <div class="Section1">
    <table border="1" cellpadding="1">
      <tr>
        <td>
          <p>Document Number:</p>
        </td>

        <td>
          <p>N3269=11-0039</p>
        </td>
      </tr>

      <tr>
        <td>
          <p>Date:</p>
        </td>

        <td>
          <p>2011-03-24</p>
        </td>
      </tr>

      <tr>
        <td>
          <p>Project:</p>
        </td>

        <td>
          <p>Programming Language C++</p>
        </td>
      </tr>
    </table>

    <p>Peter Sommerlad &lt;<a href=
    "mailto:peter.sommerlad@hsr.ch">peter.sommerlad@hsr.ch</a>&gt;</p>

    <h1>N3269: shared_future(future&lt;R&gt;&amp;&amp; rhs) should be allowed to throw</h1>

    <h2>Problem</h2>
<p>Requiring the constructor <tt>shared_future(future&lt;R&gt;&amp;&amp; rhs)</tt> 
not to throw is a pessimisation of the case where a future is returned from a call to 
<tt>async(function,launch::deferred)</tt> and possible other cases.
</p><p>
Such a future not dealing with multiple threads
only needs to keep (a copy of) the function to be called it later. However, 
creating a shared_future from that future will require more infrastructure,
like space for the value of type R, an exception_ptr,
and a synchronized reference counter for the shared_future's
instances. 
</p><p>
Enforcing the constructor <tt>shared_future(future&lt;R&gt;&amp;&amp; rhs)</tt>
not to throw, implies that any implementation of future will need to pre-allocate
space for <tt>shared_future</tt>'s infrastructure, that also requires an operating system
resource for synchronization, regardless if is ever needed. 
</p>
<p>All this came up when discussing D/N3267 and Concurrency Working Group decided that 
the constructor <tt>shared_future(future&lt;R&gt;&amp;&amp; rhs)</tt>  should be allowed to 
throw.
    <h2>Proposed Changes</h2>
    
<ol>
<li>In 30.6.7 [futures.shared_future] after p.3 <tt>shared_future</tt> synopsis
remove <tt>noexcept</tt>:
<p>
<blockquote>
<tt>shared_future(future&lt;R&gt;&amp;&amp; rhs) <del>noexcept</del>;</tt> 
</blockquote>
</li>
<li>In 30.6.7 [futures.shared_future] after p.8 remove <tt>noexcept</tt>
and insert the following paragraphs describing this constructor 
before <tt>shared_future(shared_future&lt;R&gt;&amp;&amp; rhs) noexcept;</tt>:
<p>
<blockquote>
<tt>shared_future(future&lt;R&gt;&amp;&amp; rhs) <del>noexcept</del>;</tt> 
<p/>
<blockquote>
<p>
? <ins><em>Effects</em>:</ins>
<ul>
<li><ins>
constructs a <tt>shared_future</tt> object that refers to the 
shared state that was originally referred to by <tt>rhs</tt> (if any).
</ins></li><li><ins>
If the constructor exits with an exception,
<tt>rhs</tt> shall remain unchanged.
</ins></li>
</ul>
</p><p>
? <ins><em>Postconditions</em>:</ins></p>
<ul>
<li><ins>
<tt>valid()</tt> returns the same value as <tt>rhs.valid()</tt> returned prior 
to the constructor invocation.
</ins></li>
<li><ins><tt>rhs.valid() == false</tt>. </ins>
</li>
</ul>
</ins>
</blockquote>
</blockquote>
</li>
</ol>

  </div>
</body>
</html>
