std::thread::join – cppreference.com
Aus cppreference.com
<metanoindex/>
<tbody> </tbody>
|
|
(seit C++11) | |
Blockiert den aktuellen Thread, bis das Gewinde durch *this identifiziert beendet seine Ausführung .
Original:
Blocks the current thread until the thread identified by *this finishes its execution.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
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.
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.
Ausnahmen
std::system_error wenn joinable() == false oder ein Fehler auftritt .
Original:
std::system_error if joinable() == false or an error occurs.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Beispiel
#include <iostream> #include <thread> #include <chrono> void foo() { // simulate expensive operation std::this_thread::sleep(std::chrono::seconds(1)); } void bar() { // simulate expensive operation std::this_thread::sleep(std::chrono::seconds(1)); } int main() { std::cout << "starting first helper...\n"; std::thread helper1(foo); std::cout << "starting second helper...\n"; std::thread helper2(bar); std::cout << "waiting for helpers to finish...\n"; helper1.join(); helper2.join(); std::cout << "done!\n"; }
Output:
starting first helper... starting second helper... waiting for helpers to finish... done!
Siehe auch
| Thread lösen, so dass er unabhängig vom Thread Handle ausgeführt werden kann (öffentliche Elementfunktion) [edit] | |
| prüft, ob der Thread joinable ist, d.h., möglicherweise parallel läuft (öffentliche Elementfunktion) [edit] | |