I’m following the executor proposals for quite some time and I’m interested in writing my own executors. There is one detail however which is puzzling me since the beginning. I remember some talk which said that executors are supposed to be lightweight objects so I assume they are essentially pointers to the execution context similar to iterators are pointers to the buffers of containers. If this is true, then I don’t know how the following implementation detail of then() found at https://github.com/jaredhoberock/future is allowed to store the one way executor safely and invoke execute() on it at some later point in time. What if the execution context’s destructor has already been called by the time the future gets ready?
template<class Executor, class Function>
void set_continuation(const Executor& exec, Function&& f)
{
// create a continuation that calls execution::execute()
auto continuation = [exec, f = move(f)] (experimental::future<T> predecessor_future) mutable
{
execution::execute(exec, [f = move(f), predecessor_future = move(predecessor_future)] () mutable
{
f(move(predecessor_future));
});
};
unique_lock<mutex> lock(this->mutex_);
if(this->is_ready_)
{
// the state is ready, invoke the continuation immediately
// unlock here so that the future passed to the continuation below doesn't block in .get()
lock.unlock();
continuation(this->to_future());
}
else
{
// the state is not yet ready, store the continuation for later
this->continuation_ = move(continuation);
}
}
I see three alternatives:
Maybe I misunderstood the papers, please clarify. Having some executors implemented in terms of shared_ptr or weak_ptr and forwarding executors instead of copying makes most sense to me.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussio...@isocpp.org.
To post to this group, send email to std-dis...@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.