Compartir vía


funciones<thread>

El <thread> encabezado proporciona las siguientes funciones:

get_id

Identifica de forma única el subproceso de ejecución actual.

thread::id get_id() noexcept;

Valor devuelto

Objeto de tipo thread::id que identifica de forma única el subproceso actual de ejecución.

Example

#include <iostream>
#include <thread>

int main()
{
    std::thread::id current_thread_id = std::this_thread::get_id();
    std::cout << "Current thread id: " << current_thread_id;
}
Current thread id: 16196

sleep_for

Bloquea el subproceso de llamada.

template <class Rep, class Period>
void sleep_for(const chrono::duration<Rep, Period>& Rel_time);

Parámetros

Rel_time
Objeto duration que especifica un intervalo de tiempo.

Comentarios

La función bloquea el subproceso que realiza la llamada durante al menos el tiempo especificado por Rel_time. Esta función no produce ninguna excepción.

sleep_until

Bloquea el subproceso de llamada al menos hasta la hora especificada.

template <class Clock, class Duration>
void sleep_until(const chrono::time_point<Clock, Duration>& Abs_time);

Parámetros

Abs_time
Representa un punto en el tiempo.

Comentarios

Esta función no produce ninguna excepción.

swap

Intercambia los estados de dos objetos thread.

void swap(thread& Left, thread& Right) noexcept;

Parámetros

Left
Objeto thread izquierdo.

Right
Objeto thread derecho.

Comentarios

La función llama a Left.swap(Right).

yield

Indica al sistema operativo que ejecute otros subprocesos, incluso si el subproceso actual seguiría ejecutándose en condiciones normales.

inline void yield() noexcept;

Consulte también

<thread>