<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2245: packaged_task::reset() memory allocation</title>
<meta property="og:title" content="Issue 2245: packaged_task::reset() memory allocation">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2245.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#Resolved">Resolved</a> status.</em></p>
<h3 id="2245"><a href="lwg-defects.html#2245">2245</a>. <code>packaged_task::reset()</code> memory allocation</h3>
<p><b>Section:</b> 32.10.10.2 <a href="https://wg21.link/futures.task.members">[futures.task.members]</a> <b>Status:</b> <a href="lwg-active.html#Resolved">Resolved</a>
 <b>Submitter:</b> Jonathan Wakely <b>Opened:</b> 2013-03-05 <b>Last modified:</b> 2017-03-20</p>
<p><b>Priority: </b>3
</p>
<p><b>View all other</b> <a href="lwg-index.html#futures.task.members">issues</a> in [futures.task.members].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Resolved">Resolved</a> status.</p>
<p><b>Discussion:</b></p>

<p>
The effects of <code>packaged_task::reset()</code> result in memory allocation, but
don't allow a user to provide an allocator.
<p/>
<code>packaged_task::reset()</code> needs to be overloaded like so:
</p>

<blockquote><pre>
template&lt;class Alloc&gt;  
void reset(const Alloc&amp;);
</pre></blockquote>

<p>
Alternatively, the effects of <code>reset()</code> need to require the same allocator is used 
as at construction, which would require the constructor to store the allocator for later use.
<p/>
I like to remark that GCC at the moment uses the second option, i.e. the allocator passed to the constructor 
(if any) is used to create the new shared state, because this didn't require any change to the
interface.
</p>

<p><i>[2015-02 Cologne]</i></p>

<p>
Handed over to SG1.
</p>

<p><i>[2015-05 Lenexa, SG1 response]</i></p>

<p>
No strong opinions in SG1, and this is really an LWG issue.  Back to you.
</p>

<p><i>[2016-08-02 Chicago, Billy O'Neal comments and suggests concrete wording]</i></p>

<p>
Talked this over with Alasdair, who says there's little desire to allow the <code>packaged_task</code> to 
be change allocators after initial construction, making what libstdc++ does already the "right thing." 
A clarification note is still necessary to indicate that the allocator supplied to the 
<code>allocator_arg_t</code> constructor is to be used.
</p>
<p>Wed PM: Move to Tentatively Ready</p>

<p><i>[2016-09-08]</i></p>

<p>Alisdair requests change to Review.</p>

<p><i>[2017-03-03, Kona]</i></p>

<p>This was resolved by adopting <a href="lwg-defects.html#2921" title="packaged_task and type-erased allocators (Status: C++17)">2921</a><sup><a href="https://cplusplus.github.io/LWG/issue2921" title="Latest snapshot">(i)</a></sup>, which removed the constructors that take allocators.</p>


<p id="res-2245"><b>Proposed resolution:</b></p>
<p>
This wording is relative to N4606
</p>

<ol>
<li><p>Change 32.10.10.2 <a href="https://wg21.link/futures.task.members">[futures.task.members]</a> as indicated:</p>

<blockquote>
<pre>
void reset();
</pre>
<blockquote>
<p>
-22- <i>Effects:</i> 
</p>
<ul>
<li><p><ins>if the shared state associated with <code>*this</code> was created via the <code>packaged_task(F&amp;&amp; f)</code> 
constructor, a</ins><del>A</del>s if <code>*this = packaged_task(std::move(f))</code>, where <code>f</code> is the task stored in 
<code>*this</code>.</p></li>
<li><p><ins>if the shared state associated with <code>*this</code> was created via the 
<code>packaged_task(allocator_arg_t, Allocator&amp; a, F&amp;&amp;)</code> constructor, as if 
<code>*this = packaged_task(allocator_arg, a, std::move(f))</code>, where <code>a</code> is the allocator used to allocate 
the shared state associated with <code>*this</code>, and <code>f</code> is the task stored in <code>*this</code>.</ins></p></li>
</ul>
<p>
[<i>Note:</i> This constructs a new shared state for <code>*this</code>. The old state is abandoned 
(30.6.4). &mdash; <i>end note</i>]
<p/>
-23- <i>Throws:</i>
</p>
<ul>
<li><p><ins>if no allocator was used,</ins> <code>bad_alloc</code> if memory for the new shared state could not be allocated.</p></li>
<li><p><ins>if an allocator was used, any exception thrown by <code>std::allocator_traits&lt;Allocator&gt;::template 
rebind_traits&lt;<i>unspecified</i>&gt;::allocate</code>.</ins></p></li>
<li><p>any exception thrown by the move constructor of the task stored in the shared state.</p></li>
<li><p><code>future_error</code> with an error condition of <code>no_state</code> if <code>*this</code> has no shared state.</p></li>
</ul>
</blockquote>
</blockquote>
</li>
</ol>





</body>
</html>
