C++ thread declare a thread before creating it. code example
Example 1: thread c++
#include <iostream>
#include <thread>
void foo()
{
}
void bar(int x)
{
}
int main()
{
std::thread first (foo);
std::thread second (bar,0);
std::cout << "main, foo and bar now execute concurrently...\n";
first.join();
second.join();
std::cout << "foo and bar completed.\n";
return 0;
}
Example 2: c++ create thread
void task1(std::string msg)
{
std::cout << "task1 says: " << msg;
}
std::thread t1(task1, "Hello");
t1.join();