Jump to content

C++: Difference between revisions

91 bytes added ,  27 March 2020
Line 180: Line 180:
Basic Usage:
Basic Usage:
<syntaxhighlight lang="C++">
<syntaxhighlight lang="C++">
std::thread my_thread = new std::thread(thread_function);
std::thread my_thread(thread_function);
// or
// Calling methods
std::thread my_thread = new std::thread(&Class::method, this));
// You can also pass in parameters as usual
 
std::thread my_thread(&Class::method, this));
// Lambda functions
std::thread my_thread([&]() {
// do something
});


// Wait for thread to finish
// Wait for thread to finish