std::stop_c...op_callback(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’… NAME πŸ’…

okay bestie, this is the std::stop_callback::~stop_callback page β€” the destructor β€” from the C++ Standard Libary manual (yep, that's the header spelling, no shade πŸ’€), and the page id is std::stop_c...op_callback(3). The name entry is literally: std::stop_callback::~stop_callback - std::stop_callback::~stop_callback.

✨ Synopsis ✨

~stop_callback();

since C++20 πŸ¦‹

So ~stop_callback() destroys the stop_callback object. πŸ’₯

If *this has a stop_token with associated stop-state, it deregisters the callback from it. πŸŽ€

If the callback function is being invoked concurrently on another thread, the destructor does not complete until the callback function invocation is complete. 😭 If the callback function is being invoked on the same thread the destructor is being invoked on, then the destructor returns without waiting for callback invocation to complete (see Notes). πŸ‘€

🧚 Notes 🧚

The stop_callback destructor is designed to prevent race conditions and deadlocks. πŸ”₯ If another thread is currently invoking the callback, then the destructor cannot return until that completes β€” or else the function object could potentially be destroyed while it is being executed. πŸ’€ The callback function is not required to be neither copyable nor movable - it lives in the stop_callback object itself even after registration. 🫢

On the other hand, if the current thread invoking the destructor is the same thread that is invoking the callback, then the destructor cannot wait or else a deadlock would occur. πŸ˜΅β€πŸ’« It is possible and valid for the same thread to be destroying the stop_callback while it is invoking its callback function, because the callback function might itself destroy the stop_callback, directly or indirectly. 🌈


mwah πŸ’– source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: std::stop_c...op_callback(3).

πŸ“¦ where this page comes from