Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::stop_callback<Callback>::stop_callback

      From cppreference.com
      <cpp‎ |thread‎ |stop callback
       
       
      Concurrency support library
      Threads
      (C++11)
      (C++20)
      this_thread namespace
      (C++11)
      (C++11)
      (C++11)
      Cooperative cancellation
      Mutual exclusion
      Generic lock management
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      Condition variables
      (C++11)
      Semaphores
      Latches and Barriers
      (C++20)
      (C++20)
      Futures
      (C++11)
      (C++11)
      (C++11)
      Safe reclamation
      Hazard pointers
      Atomic types
      (C++11)
      (C++20)
      Initialization of atomic types
      (C++11)(deprecated in C++20)
      (C++11)(deprecated in C++20)
      Memory ordering
      (C++11)(deprecated in C++26)
      Free functions for atomic operations
      Free functions for atomic flags
       
       
      template<class C>
      explicit stop_callback(conststd::stop_token& st, C&& cb)noexcept(/*see below*/);
      (1)(since C++20)
      template<class C>
      explicit stop_callback(std::stop_token&& st, C&& cb)noexcept(/*see below*/);
      (2)(since C++20)
      stop_callback(const stop_callback&)= delete;
      (3)(since C++20)
      stop_callback( stop_callback&&)= delete;
      (4)(since C++20)

      Constructs a newstop_callback object, saving and registering thecb callback function into the givenstd::stop_token's associated stop-state, for later invocation if stop is requested on the associatedstd::stop_source.

      1) Constructs astop_callback for the givenststd::stop_token (copied), with the given invocable callback functioncb.
      2) Constructs astop_callback for the givenststd::stop_token (moved), with the given invocable callback functioncb.
      3,4)stop_callback is neitherCopyConstructible norMoveConstructible.

      Both constructors participate overload resolution only ifCallback andC satisfyconstructible_from ofstd::constructible_from<Callback, C>. IfCallback andC satisfy the concept but fail to satisfy its semantic requirement, the behavior is undefined.

      [edit]Parameters

      st - astd::stop_token object to register thisstop_callback object with
      cb - the type to invoke if stop is requested

      [edit]Exceptions

      1,2)
      noexcept specification:  
      noexcept(std::is_nothrow_constructible_v<Callback, C>)
      Any exception thrown by constructor-initializing the given callback into thestop_callback object.

      [edit]Notes

      Ifst.stop_requested()==true for the passed-instd::stop_token, then the callback function is invoked in the current thread before the constructor returns.

      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/thread/stop_callback/stop_callback&oldid=161246"

      [8]ページ先頭

      ©2009-2025 Movatter.jp