std::this_thread::yield
Aus cppreference.com
![]() | This page has been machine-translated from the English version of the wiki using Google Translate. The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
definiert in Header <thread> | ||
void yield(); | (seit C++11) | |
Stellt einen Hinweis für die Umsetzung, um die Ausführung von Threads verschieben, so dass andere Threads zu laufen .
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.
You can help to correct and verify the translation. Click here for instructions.
[Bearbeiten]Parameter
(None)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[Bearbeiten]Rückgabewert
(None)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[Bearbeiten]Beispiel
#include <iostream>#include <chrono>#include <thread> // "busy sleep" while suggesting that other threads run // for a small amount of timevoid 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";}
Possible output:
waited for 128 microseconds