Files
cppdraft_translate/cppdraft/exec/sysctxrepl.md
2025-10-25 03:02:53 +03:00

10 KiB
Raw Blame History

[exec.sysctxrepl]

33 Execution control library [exec]

33.16 Namespace system_context_replaceability [exec.sysctxrepl]

33.16.1 General [exec.sysctxrepl.general]

1

#

Facilities in the system_context_replaceability namespace allow users to replace the default implementation of parallel_scheduler.

33.16.2 query_parallel_scheduler_backend [exec.sysctxrepl.query]

🔗

shared_ptr<parallel_scheduler_backend> query_parallel_scheduler_backend();

1

#

query_parallel_scheduler_backend() returns the implementation object for a parallel scheduler.

2

#

Returns: A non-null shared pointer to an object that implements the parallel_scheduler_backend interface.

3

#

Remarks: This function is replaceable ([dcl.fct.def.replace]).

namespace std::execution::system_context_replaceability {struct receiver_proxy {virtual ~receiver_proxy() = default; protected:virtual bool query-env(unspecified) noexcept = 0; // exposition onlypublic:virtual void set_value() noexcept = 0; virtual void set_error(exception_ptr) noexcept = 0; virtual void set_stopped() noexcept = 0; template<class P, class-type Query> optional

try_query(Query q) noexcept; }; struct bulk_item_receiver_proxy : receiver_proxy {virtual void execute(size_t, size_t) noexcept = 0; };}

4

#

receiver_proxy represents a receiver that will be notified by the implementations of parallel_scheduler_backend to trigger the completion operations.

bulk_item_receiver_proxy is derived from receiver_proxy and is used for bulk_chunked and bulk_unchunked customizations that will also receive notifications from implementations of parallel_scheduler_backend corresponding to different iterations.

🔗

template<class P, [class-type](execution.syn#concept:class-type "33.4Header <execution> synopsis[execution.syn]") Query> optional<P> [try_query](#lib:try_query "33.16.2query_­parallel_­scheduler_­backend[exec.sysctxrepl.query]")(Query q) noexcept;

5

#

Mandates: P is a cv-unqualified non-array object type.

6

#

Returns: Let env be the environment of the receiver represented by *this.

If

Query is not a member of an implementation-defined set of supported queries; or

P is not a member of an implementation-defined set of supported result types for Query; or

the expression q(env) is not well-formed or does not have type cv P,

then returns nullopt.

Otherwise, returns q(env).

7

#

Remarks: get_stop_token_t is in the implementation-defined set of supported queries, andinplace_stop_token is a member of the implementation-defined set of supported result types for get_stop_token_t.

33.16.3 Class parallel_scheduler_backend [exec.sysctxrepl.psb]

namespace std::execution::system_context_replaceability {struct parallel_scheduler_backend {virtual ~parallel_scheduler_backend() = default; virtual void schedule(receiver_proxy&, span) noexcept = 0; virtual void schedule_bulk_chunked(size_t, bulk_item_receiver_proxy&, span) noexcept = 0; virtual void schedule_bulk_unchunked(size_t, bulk_item_receiver_proxy&, span) noexcept = 0; };}

🔗

virtual void schedule(receiver_proxy& r, span<byte> s) noexcept = 0;

1

#

Preconditions: The ends of the lifetimes of *this, the object referred to by r, and any storage referenced by s all happen after the beginning of the evaluation of the call to set_value, set_error, or set_done on r (see below).

2

#

Effects: A derived class shall implement this function such that:

  • (2.1)

    One of the following expressions is evaluated:

r.set_value(), if no error occurs, and the work is successful;

r.set_error(eptr), if an error occurs, where eptr is an object of type exception_ptr;

r.set_stopped(), if the work is canceled.

  • (2.2)

    Any call to r.set_value() happens on an execution agent of the execution context represented by *this.

3

#

Remarks: The storage referenced by s may be used by *this as temporary storage for the duration of the operation launched by this call.

🔗

virtual void schedule_bulk_chunked(size_t n, bulk_item_receiver_proxy& r, span<byte> s) noexcept = 0;

4

#

Preconditions: The ends of the lifetimes of *this, the object referred to by r, and any storage referenced by s all happen after the beginning of the evaluation of one of the expressions below.

5

#

Effects: A derived class shall implement this function such that:

  • (5.1)

    Eventually, one of the following expressions is evaluated:

r.set_value(), if no error occurs, and the work is successful;

r.set_error(eptr), if an error occurs, where eptr is an object of type exception_ptr;

r.set_stopped(), if the work is canceled.

  • (5.2)

    If r.execute(b, e) is called, then b and e are in the range [0, n] andb < e.

  • (5.3)

    For each i in [0, n), there is at most one call to r.execute(b, e) such that i is in the range [b, e).

  • (5.4)

    If r.set_value() is called, then for each i in [0, n), there is exactly one call to r.execute(b, e) such that i is in the range [b, e).

  • (5.5)

    All calls to execute on r happen before the call to either set_value, set_error, or set_stopped on r.

  • (5.6)

    All calls to execute and set_value on r are made on execution agents of the execution context represented by *this.

6

#

Remarks: The storage referenced by s may be used by *this as temporary storage for the duration of the operation launched by this call.

🔗

virtual void schedule_bulk_unchunked(size_t n, bulk_item_receiver_proxy& r, span<byte> s) noexcept = 0;

7

#

Preconditions: The ends of the lifetimes of *this, the object referred to by r, and any storage referenced by s all happen after the beginning of the evaluation of one of the expressions below.

8

#

Effects: A derived class shall implement this function such that:

  • (8.1)

    Eventually, one of the following expressions is evaluated:

r.set_value(), if no error occurs, and the work is successful;

r.set_error(eptr), if an error occurs, where eptr is an object of type exception_ptr;

r.set_stopped(), if the work is canceled.

  • (8.2)

    If r.execute(b, e) is called, then b is in the range [0, n) ande is equal to b + 1. For each i in [0, n), there is at most one call to r.execute(i, i + 1).

  • (8.3)

    If r.set_value() is called, then for each i in [0, n), there is exactly one call to r.execute(i, i + 1).

  • (8.4)

    All calls to execute on r happen before the call to either set_value, set_error, or set_stopped on r.

  • (8.5)

    All calls to execute and set_value on r are made on execution agents of the execution context represented by *this.

9

#

Remarks: The storage referenced by s may be used by *this as temporary storage for the duration of the operation launched by this call.