[patch] Define std::promise::set_value_at_thread_exit() etc.
Jonathan Wakely
jwakely@redhat.com
Tue Dec 2 01:51:00 GMT 2014
On 23/10/14 17:00 +0100, Jonathan Wakely wrote:
>This adds:
> std::notify_all_at_thread_exit()
> std::promise<>::set_value_at_thread_exit()
> std::promise<>::set_exception_at_thread_exit()
> std::packaged_task<>::make_ready_at_thread_exit()
>
>There's a linked list of callbacks that run after TLS destructors
>(called by a pthread_key_create destructor) to make shared states
>ready and notify condition variables.
>
>The core of the change to futures is that the shared state is
>considered ready when _M_ready == true, instead of when _M_result !=
>nullptr, so that we can store a result in _M_result without making it
>ready. The callback that would make it ready at thread exit stores a
>weak_ptr so it can safely check whether the shared state has already
>been destroyed before thread exit (see thread c++std-parallel-1162 on
>the SG1 list for related discussion).
>
>Tested x86_64-linux, I'd like to commit this next week some time.
This is a slightly updated version of the patch, the differences are:
- added some comments to document the code better
- renamed _M_set_result_aside to _M_set_delayed_result and
_M_run_not_ready to _M_run_delayed
- changed _Task_state::_M_run and _M_run_delayed to take arguments by
reference, to avoid unnecessary copies
- changed _Deferred_state::_M_has_deferred to always return true (not
just before the deferred function has been run) so it doesn't
require the caller to own the mutex, which doesn't change behaviour
because it will never be called when the state is already ready
anyway
- changed ~_Async_state_impl to call _M_thread.join() directly instead
of via std::call_once, because in the destructor there can be no
other threads trying to join it
Tested x86_64-linux + powerpc64-linux, committed to trunk.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.txt
Type: text/x-patch
Size: 30273 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20141202/b948afdc/attachment.bin>
More information about the Libstdc++
mailing list