Boost C++ Libraries: Ticket #9425: Boost promise & future does not use supplied allocator for value storage https://svn.boost.org/trac10/ticket/9425 <p> Presently Boost.Thread's promise and future does not use the constructor supplied allocator instance to allocate the shared state value, and instead uses operator new. This breaks with the C++11 standard behaviour. </p> <p> Niall </p> <p> Copy and paste from email dialogue with Vicente: </p> <p> Le 20/11/13 18:07, Niall Douglas a écrit : </p> <blockquote class="citation"> <p> Vicente, </p> <p> Just checking something: VS2013 is giving me a warning about unaligned allocation when I try to do this: </p> <ol><li>I have BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS defined. </li></ol><ol start="2"><li>I initialise a promise&lt;Int256&gt; like this: </li></ol><p> boost::promise&lt;Int256_type&gt;(boost::allocator_arg_t(), aligned_allocator&lt;Int256, 32&gt;()) </p> <ol start="3"><li>When I try to use set_value() on the promise, I then see the warning </li></ol><p> due to this function around line 551 in struct future_traits: </p> <blockquote> <p> static void init(storage_type&amp; storage,source_reference_type t) { </p> <blockquote> <p> storage.reset(new T(t)); </p> </blockquote> <p> } </p> </blockquote> <p> which implies that the allocator configured for the type Int256 is not used because you are using operator new instead of the allocator? </p> <p> Maybe this is me misunderstanding how futures and promises use an externally supplied allocator. Your future/promise correctly uses the allocator to initialise shared_state, but internally to shared_state it then creates a scoped_ptr to hold the actual value storage and that is where operator new is being invoked to store the value instead of the allocator. </p> <p> If this was not intentional, can I suggest that instead of keeping a scoped_ptr to the value, you could instead keep the value itself stored in shared_state which then would have the correct alignment? You could use placement new and placement delete to construct/destruct the instance without affecting storage with a separate flag elsewhere indicating validity. Alternatively, I'm sure there must be some way of preallocating shared_state storage while the type of the custom allocator is still available. </p> <p> Thanks, Niall </p> </blockquote> <p> Hi Niall, </p> <p> you are right. I missed this allocation. </p> <p> I'm too busy currently. It would be greate if you have the time to provide a patch. </p> <p> Best, Vicente </p> <p> P.S. Please, create a ticket so that I don't forget this issue. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9425 Trac 1.4.3 viboes Sat, 23 Nov 2013 18:16:19 GMT owner, status changed https://svn.boost.org/trac10/ticket/9425#comment:1 https://svn.boost.org/trac10/ticket/9425#comment:1 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Anthony Williams</span> to <span class="trac-author">viboes</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket viboes Sun, 24 Nov 2013 15:27:44 GMT version, milestone changed https://svn.boost.org/trac10/ticket/9425#comment:2 https://svn.boost.org/trac10/ticket/9425#comment:2 <ul> <li><strong>version</strong> <span class="trac-field-old">Boost Development Trunk</span> → <span class="trac-field-new">Boost 1.55.0</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.56.0</span> → <span class="trac-field-new">To Be Determined</span> </li> </ul> Ticket viboes Wed, 26 Feb 2014 21:37:35 GMT severity changed https://svn.boost.org/trac10/ticket/9425#comment:3 https://svn.boost.org/trac10/ticket/9425#comment:3 <ul> <li><strong>severity</strong> <span class="trac-field-old">Showstopper</span> → <span class="trac-field-new">Problem</span> </li> </ul> <p> Moved to problem as this doesn't prevent the use of the library. </p> Ticket viboes Sun, 07 Sep 2014 17:45:36 GMT <link>https://svn.boost.org/trac10/ticket/9425#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9425#comment:4</guid> <description> <p> After a first analysis, I think that we need to use unique_ptr&lt;T&gt; instead of scoped_ptr&lt;T&gt;. The problem is that we need a type erased deleter so that we can instantiate with default_delete&lt;T&gt; and with a specific allocator_delete&lt;T,A&gt;. </p> <pre class="wiki">unique_ptr&lt;T, erased_delete&lt;T&gt;&gt; </pre><p> I will start by refactoring the code, so that it is possible to set the value using an erased unique_ptr&lt;&gt; instead of the current source_reference_type and rvalue_source_type. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Tue, 09 Sep 2014 06:27:01 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9425#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9425#comment:5</guid> <description> <p> After some trials, I have fall on issues mixing the old Boost.Thread move emulation and boost::movelib_unique_ptr&lt;T,D&gt;, which is of course not aware of this old emulation. </p> <p> I suspect that this issue could only be fixed on a version that doesn't supports the old move emulation. </p> <p> I'm wondering if it will be a good idea to branch a specific future.hpp implementation that doesn't supports the old move semantics and is aligned with version 4. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Niall Douglas</dc:creator> <pubDate>Wed, 10 Sep 2014 14:41:49 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9425#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9425#comment:6</guid> <description> <p> FYI Vicente I have finished concurrent_unordered_map. My next task is non-allocating future-promise based on expected&lt;T, E&gt;, and I have been in discussions with Louis Dionne about the monadic part of the design as I do not fully understand it. Once those are complete I shall begin work. </p> <p> Niall </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 14 Sep 2014 12:10:04 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9425#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9425#comment:7</guid> <description> <p> An alternative could be to use optional&lt;T&gt; (waiting for expected&lt;T&gt;). </p> <p> With optional&lt;T&gt; there will be no internal allocation, and so the issue will be a non-issue. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 14 Sep 2014 14:20:29 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9425#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9425#comment:8</guid> <description> <p> Unfortunately, optional&lt;T&gt; doesn't supports emulated move semantics with Boost.Move. This means that optional&lt;T&gt; could be used only on C++11 compilers supporting move semantics. </p> <p> Niall, would this be enough for you? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 14 Sep 2014 19:55:09 GMT</pubDate> <title>milestone changed https://svn.boost.org/trac10/ticket/9425#comment:9 https://svn.boost.org/trac10/ticket/9425#comment:9 <ul> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.57.0</span> </li> </ul> <p> <a class="ext-link" href="https://github.com/boostorg/thread/commit/f73007910af7a5ef68bc5d722d262b54dd0cf3ca"><span class="icon">​</span>https://github.com/boostorg/thread/commit/f73007910af7a5ef68bc5d722d262b54dd0cf3ca</a> </p> Ticket Niall Douglas Mon, 15 Sep 2014 10:48:14 GMT <link>https://svn.boost.org/trac10/ticket/9425#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9425#comment:10</guid> <description> <p> To be clear, I personally no longer need allocating shared_ptr now the non-allocating future-promise is shortly to become real. My original need for allocating shared_ptr was to avoid unnecessary memory allocation, so I could recycle the buffers. That won't be necessary soon as there will be no buffers. </p> <p> Also, if I am successful, I should hope the C++ 17 standard will change promise-future to match ours. And then allocation will become deprecated. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Mon, 15 Sep 2014 19:54:06 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9425#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9425#comment:11</guid> <description> <p> Ok. I consider then that this bug is closed. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Tue, 23 Sep 2014 00:05:28 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/9425#comment:12 https://svn.boost.org/trac10/ticket/9425#comment:12 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> Ticket