cpp threads 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 threads
#include <thread>
void foo()
{
}
int main()
{
std::thread first (foo);
first.join();
}
Example 3: what is thread in c++
sequence of instructions that can be executed concurrently