std::this_thread::yield - cppreference.com
Espaços nominais
Variantes
Ações

std::this_thread::yield

De cppreference.com

<metanoindex/>

 
 
Biblioteca de suporte a discussão
Threads
Original:
Threads
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
this_thread namespace
Original:
this_thread namespace
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
(C++11)
(C++11)
Exclusão mútua
Original:
Mutual exclusion
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
Gestão de bloqueio genérico
Original:
Generic lock management
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
(C++11)
(C++11)
(C++11)(C++11)(C++11)
Variáveis ​​de condição
Original:
Condition variables
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
Futuros
Original:
Futures
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
(C++11)
(C++11)
(C++11)
 
<tbody> </tbody>
Fornece uma dica para a implementação de remarcar a execução de threads, permitindo que outros segmentos para executar.
Original:
Provides a hint to the implementation to reschedule the execution of threads, allowing other threads to run.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Parâmetros

(Nenhum)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Valor de retorno

(Nenhum)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Exemplo

#include <iostream>
#include <chrono>
#include <thread>

// "busy sleep" while suggesting that other threads run 
// for a small amount of time
void little_sleep(std::chrono::microseconds us)
{
    auto start = std::chrono::high_resolution_clock::now();
    auto end = start + us;
    do {
        std::this_thread::yield();
    } while (std::chrono::high_resolution_clock::now() < end);
}

int main()
{
    auto start = std::chrono::high_resolution_clock::now();

    little_sleep(std::chrono::microseconds(100));

    auto elapsed = std::chrono::high_resolution_clock::now() - start;
    std::cout << "waited for "
              << std::chrono::duration_cast<std::chrono::microseconds>(elapsed).count()
              << " microseconds\n";
}

Potencial saída:

waited for 128 microseconds