+Exec* Exec::wait()
+{
+ if (state_ == State::INITED)
+ start();
+ simcall_execution_wait(pimpl_);
+ state_ = State::FINISHED;
+ on_completion(*Actor::self(), *this);
+ return this;
+}
+
+Exec* Exec::wait_for(double)
+{
+ THROW_UNIMPLEMENTED;
+}
+
+int Exec::wait_any_for(std::vector<ExecPtr>* execs, double timeout)
+{
+ std::unique_ptr<kernel::activity::ExecImpl* []> rexecs(new kernel::activity::ExecImpl*[execs->size()]);
+ std::transform(begin(*execs), end(*execs), rexecs.get(),
+ [](const ExecPtr& exec) { return static_cast<kernel::activity::ExecImpl*>(exec->pimpl_.get()); });
+ return simcall_execution_waitany_for(rexecs.get(), execs->size(), timeout);
+}
+
+Exec* Exec::cancel()
+{
+ kernel::actor::simcall([this] { boost::static_pointer_cast<kernel::activity::ExecImpl>(pimpl_)->cancel(); });
+ state_ = State::CANCELED;
+ return this;
+}
+
+void intrusive_ptr_release(simgrid::s4u::Exec* e)
+{
+ if (e->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
+ std::atomic_thread_fence(std::memory_order_acquire);
+ delete e;
+ }
+}
+
+void intrusive_ptr_add_ref(simgrid::s4u::Exec* e)
+{
+ e->refcount_.fetch_add(1, std::memory_order_relaxed);
+}
+
+/** @brief change the execution bound
+ * This means changing the maximal amount of flops per second that it may consume, regardless of what the host may
+ * deliver. Currently, this cannot be changed once the exec started.
+ */
+ExecPtr Exec::set_bound(double bound)
+{
+ xbt_assert(state_ == State::INITED, "Cannot change the bound of an exec after its start");
+ bound_ = bound;
+ return this;
+}
+ExecPtr Exec::set_timeout(double timeout)
+{
+ xbt_assert(state_ == State::INITED, "Cannot change the bound of an exec after its start");
+ timeout_ = timeout;
+ return this;
+}
+
+ExecPtr Exec::set_name(const std::string& name)
+{
+ xbt_assert(state_ == State::INITED, "Cannot change the name of an exec after its start");
+ name_ = name;
+ return this;
+}
+
+/** @brief Retrieve the host on which this activity takes place.
+ * If it runs on more than one host, only the first host is returned.
+ */
+Host* Exec::get_host() const
+{
+ return static_cast<kernel::activity::ExecImpl*>(pimpl_.get())->get_host();
+}
+unsigned int Exec::get_host_number() const
+{
+ return static_cast<kernel::activity::ExecImpl*>(pimpl_.get())->get_host_number();
+}
+double Exec::get_start_time() const
+{
+ return (pimpl_->surf_action_ == nullptr) ? -1 : pimpl_->surf_action_->get_start_time();
+}
+double Exec::get_finish_time() const
+{
+ return (pimpl_->surf_action_ == nullptr) ? -1 : pimpl_->surf_action_->get_finish_time();
+}
+double Exec::get_cost() const
+{
+ return (pimpl_->surf_action_ == nullptr) ? -1 : pimpl_->surf_action_->get_cost();
+}
+