13 Asynchronous model [async]

13.18 Class system_executor [async.system.exec]

Class system_executor represents a set of rules where function objects are permitted to execute on any thread.

namespace std {
namespace experimental {
namespace net {
inline namespace v1 {

  class system_executor
  {
  public:
    // constructors:

    system_executor() {}

    // [async.system.exec.ops], executor operations:

    system_context& context() const noexcept;

    void on_work_started() const noexcept {}
    void on_work_finished() const noexcept {}

    template<class Func, class ProtoAllocator>
      void dispatch(Func&& f, const ProtoAllocator& a) const;
    template<class Func, class ProtoAllocator>
      void post(Func&& f, const ProtoAllocator& a) const;
    template<class Func, class ProtoAllocator>
      void defer(Func&& f, const ProtoAllocator& a) const;
  };

  bool operator==(const system_executor&, const system_executor&) noexcept;
  bool operator!=(const system_executor&, const system_executor&) noexcept;

} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std

Class system_executor satisfies the Destructible (C++ 2014 [destructible]), DefaultConstructible (C++ 2014 [defaultconstructible]), and Executor ([async.reqmts.executor]) type requirements.

To satisfy the Executor requirements for the post and defer member functions, the system executor may create thread objects to run the submitted function objects. These thread objects are collectively referred to as system threads.

13.18.1 system_executor operations [async.system.exec.ops]

system_context& context() const noexcept;

Returns: A reference to an object with static storage duration. All calls to this function return references to the same object.

template<class Func, class ProtoAllocator> void dispatch(Func&& f, const ProtoAllocator& a) const;

Effects: Equivalent to DECAY_COPY(forward<Func>(f))() (C++ 2014 [thread.decaycopy]).

template<class Func, class ProtoAllocator> void post(Func&& f, const ProtoAllocator& a) const; template<class Func, class ProtoAllocator> void defer(Func&& f, const ProtoAllocator& a) const;

Effects: If context().stopped() is false, creates an object f1 initialized with DECAY_COPY(forward<Func>(f)), and calls f1() as if in a thread of execution represented by a thread object. Any exception propagated from the execution of DECAY_COPY(forward<Func>(f))() results in a call to std::terminate.

13.18.2 system_executor comparisons [async.system.exec.comparisons]

bool operator==(const system_executor&, const system_executor&) noexcept;

Returns: true.

bool operator!=(const system_executor&, const system_executor&) noexcept;

Returns: false.