std::jthread::get_id
De cppreference.com
<tbody>
</tbody>
[[nodiscard]] std::jthread::id get_id() const noexcept; |
(desde C++20) | |
Devuelve un valor de tipo std::jthread::id que identifica el hilo asociado con *this.
Parámetros
(Ninguno)
Valor de retorno
Un valor de tipo std::jthread::id que identifica el hilo asociado con *this. Si no hay un hilo asociado, se devuelve un objeto std::jthread::id construido por defecto.
Ejemplo
Ejecuta este código
#include <iostream>
#include <thread>
#include <chrono>
void foo()
{
std::this_thread::sleep_for(std::chrono::seconds(1));
}
int main()
{
std::jthread t1(foo);
std::jthread::id t1_id = t1.get_id();
std::jthread t2(foo);
std::jthread::id t2_id = t2.get_id();
std::cout << "id de t1: " << t1_id << '\n';
std::cout << "id de t2: " << t2_id << '\n';
}
Posible salida:
id de t1: 0x35a7210f
id de t2: 0x35a311c4
Véase también
| Representa el identificador de un hilo (clase miembro pública de std::thread)
| |
| Comprueba si el objeto representa a un hilo actualmente en ejecución o a la espera de recibir un join() (función miembro pública de std::thread)
|