Namespaces
Variants

Standard library header <stop_token> (C++20)

From cppreference.net
Standard library headers

Dieser Header ist Teil der Thread-Unterstützungsbibliothek .

Inhaltsverzeichnis

Klassen

(C++20)
eine Schnittstelle zum Abfragen, ob eine std::jthread Abbruchanforderung gestellt wurde
(Klasse)
Klasse, die eine Anforderung zum Stoppen eines oder mehrerer std::jthread s repräsentiert
(Klasse)
Eine Schnittstelle zum Registrieren von Callbacks bei std::jthread -Abbruch
(Klassentemplate)
bietet eine Stop-Token-Schnittstelle, bei der ein Stop niemals möglich noch angefordert wird
(Klasse)
Ein Stopp-Token, das auf den Stopp-Zustand seines zugehörigen std::inplace_stop_source -Objekts verweist
(Klasse)
ein stoppable-source , das der alleinige Eigentümer des Stop-Zustands ist
(Klasse)
Ein Stopp-Callback für std::inplace_stop_token
(Klassentemplate)

Alias-Templates

ermittelt den Callback-Typ für einen gegebenen Stop-Token-Typ
(Alias-Template)

Konzepte

spezifiziert die grundlegende Schnittstelle von Stop-Tokens, die Abfragen nach Stop-Anforderungen ermöglicht und ob eine Stop-Anforderung möglich ist
(Konzept)
spezifiziert einen Stop-Token, der kein Stoppen erlaubt
(Konzept)

Tags

ein Tag, der für stop_source verwendet wird, um anzuzeigen, dass beim Konstruieren kein zugehöriger Stop-Zustand vorhanden ist
(Tag)

Übersicht

namespace std {
  // Stop-Token-Konzepte
  template<class CallbackFn, class Token, class Init = CallbackFn>
    concept /*stoppable-callback-for*/ = /* siehe Beschreibung */; // nur zur Darstellung
  template<class Token>
    concept stoppable_token = /* siehe Beschreibung */;
  template<class Token>
    concept unstoppable_token = /* siehe Beschreibung */;
  template<class Source>
    concept /*stoppable-source*/ = /* siehe Beschreibung */; // nur zur Darstellung
  // Klasse stop_token
  class stop_token;
  // Klasse stop_source
  class stop_source;
  // No-Shared-Stop-State-Indikator
  struct nostopstate_t {
    explicit nostopstate_t() = default;
  };
  inline constexpr nostopstate_t nostopstate{};
  // Klassentemplate stop_callback
  template<class Callback>
  class stop_callback;
  // Klasse never_stop_token
  class never_stop_token;
  // Klasse inplace_stop_token
  class inplace_stop_token;
  // Klasse inplace_stop_source
  class inplace_stop_source;
  // Klassentemplate inplace_stop_callback
  template<class CallbackFn>
    class inplace_stop_callback;
  template<class T, class CallbackFn>
    using stop_callback_for_t = T::template callback_type<CallbackFn>;
}

Stop-Token-Konzepte

namespace std {
  template<class CallbackFn, class Token, class Init = CallbackFn>
    concept /*stoppable-callback-for*/ =                         // nur zur Darstellung
      invocable<CallbackFn> &&
      constructible_from<CallbackFn, Init> &&
      requires { typename stop_callback_for_t<Token, CallbackFn>; } &&
      constructible_from<stop_callback_for_t<Token, CallbackFn>, const Token&, Init>;
  template<template<class> class>
    struct /*check-type-alias-exists*/;                          // nur zur Darstellung
  template<class Token>
    concept stoppable_token = 
      requires (const Token tok) {
        typename /*check-type-alias-exists*/<Token::template callback_type>;
        { tok.stop_requested() } noexcept -> same_as<bool>;
        { tok.stop_possible() } noexcept -> same_as<bool>;
        { Token(tok) } noexcept; // siehe implizite Ausdrucksvarianten
      } &&
      copyable<Token> &&
      equality_comparable<Token>;
  template<class Token>
    concept unstoppable_token = 
      stoppable_token<Token> &&
      requires (const Token tok) {
        requires bool_constant<(!tok.stop_possible())>::value;
      };
  template<class Source>
    concept /*stoppable-source*/ =                               // nur zur Darstellung
      requires (Source& src, const Source csrc) {
        { csrc.get_token() } -> stoppable_token;
        { csrc.stop_possible() } noexcept -> same_as<bool>;
        { csrc.stop_requested() } noexcept -> same_as<bool>;
        { src.request_stop() } -> same_as<bool>;
      };
}

Klasse std::stop_token

namespace std {
  class stop_token {
  public:
    template<class CallbackFn>
      using callback_type = stop_callback<CallbackFn>;
    // Konstruktoren, Kopieren und Zuweisung
    stop_token() noexcept = default;
    // Member-Funktionen
    void swap(stop_token&) noexcept;
    // Stopp-Behandlung
    bool stop_requested() const noexcept;
    bool stop_possible() const noexcept;
    friend bool operator==(const stop_token& lhs, const stop_token& rhs) noexcept;
    friend void swap(stop_token& lhs, stop_token& rhs) noexcept;
  private:
    shared_ptr</*unspecified*/> stop_state_; // nur zur Darstellung
  };
}

Klasse std::stop_source

namespace std {
  class stop_source {
  public:
    // Konstruktoren, Kopieren und Zuweisung
    stop_source();
    explicit stop_source(nostopstate_t) noexcept {}
    // Memberfunktionen
    void swap(stop_source&) noexcept;
    // Stopp-Behandlung
    stop_token get_token() const noexcept;
    bool stop_possible() const noexcept;
    bool stop_requested() const noexcept;
    bool request_stop() noexcept;
    friend bool
    operator==(const stop_source& lhs, const stop_source& rhs) noexcept;
    friend void swap(stop_source& lhs, stop_source& rhs) noexcept;
  private:
    shared_ptr</*unspecified*/> stop_state_; // nur zur Darstellung
  };
}

Klassentemplate std::stop_callback

namespace std {
  template<class CallbackFn>
  class stop_callback {
  public:
    using callback_type = CallbackFn;
    // Konstruktoren und Destruktor
    template<class Init>
    explicit stop_callback(const stop_token& st, Init&& init)
        noexcept(is_nothrow_constructible_v<CallbackFn, Init>);
    template<class Init>
    explicit stop_callback(stop_token&& st, Init&& init)
        noexcept(is_nothrow_constructible_v<CallbackFn, Init>);
    ~stop_callback();
    stop_callback(const stop_callback&) = delete;
    stop_callback(stop_callback&&) = delete;
    stop_callback& operator=(const stop_callback&) = delete;
    stop_callback& operator=(stop_callback&&) = delete;
  private:
    CallbackFn callback_fn_;      // nur zur Darstellung
  };
  template<class CallbackFn>
  stop_callback(stop_token, CallbackFn) -> stop_callback<CallbackFn>;
}

Klassentemplate std::never_stop_token

namespace std {
  class never_stop_token {
    struct /*callback-type*/ {       // nur zur Darstellung
      explicit /*callback-type*/(never_stop_token, auto&&) noexcept {}
    };
  public:
    template<class>
      using callback_type = /*callback-type*/;
    static constexpr bool stop_requested() noexcept { return false; }
    static constexpr bool stop_posible() noexcept { return false; }
    bool operator==(const never_stop_token&) const = default;
  };
}

Klassentemplate std::inplace_stop_token

namespace std {
  class inplace_stop_token {
  public:
    template<class CallbackFn>
      using callback_type = inplace_stop_callback<CallbackFn>;
    inplace_stop_token() = default;
    bool operator==(const inplace_stop_token&) const = default;
    // Memberfunktionen
    bool stop_requested() const noexcept;
    bool stop_possible() const noexcept;
    void swap(inplace_stop_token&) noexcept;
  private:
    const inplace_stop_source* stop_source_ = nullptr; // nur zur Darstellung
  };
}

Klassentemplate std::inplace_stop_source

namespace std {
  class inplace_stop_source {
    // Konstruktoren, Zuweisungen und Destruktor
    constexpr inplace_stop_source() noexcept;
    inplace_stop_source(inplace_stop_source&&) = delete;
    inplace_stop_source(const inplace_stop_source&) = delete;
    inplace_stop_source& operator=(inplace_stop_source&&) = delete;
    inplace_stop_source& operator=(const inplace_stop_source&) = delete;
    ~inplace_stop_source();
    // Stopp-Behandlung
    constexpr inplace_stop_token get_token() const noexcept;
    static constexpr bool stop_possible() noexcept { return true; }
    bool stop_requested() const noexcept;
    bool request_stop() noexcept;
  };
}

Klassentemplate std::inplace_stop_callback

namespace std {
  template<class CallbackFn>
  class inplace_stop_callback {
  public:
    using callback_type = CallbackFn;
    // Konstruktoren und Destruktor
    template<class Init>
    explicit inplace_stop_callback(inplace_stop_token st, Init&& init)
        noexcept(is_nothrow_constructible_v<CallbackFn, Init>);
    ~inplace_stop_callback();
    inplace_stop_callback(const inplace_stop_callback&) = delete;
    inplace_stop_callback(inplace_stop_callback&&) = delete;
    inplace_stop_callback& operator=(const inplace_stop_callback&) = delete;
    inplace_stop_callback& operator=(inplace_stop_callback&&) = delete;
  private:
    CallbackFn callback_fn_;      // nur zur Darstellung
  };
  template<class CallbackFn>
  inplace_stop_callback(inplace_stop_token, CallbackFn) 
    -> inplace_stop_callback<CallbackFn>;
}