In [ ]:
#include <thread>
#include <iostream>
#include <vector>


All the threads utilities are located in the thread header. An interesting thing in this first example is the call to the join() function. Calling this function forces the current thread to wait for the other one (in this case, the main thread has to wait for the thread t1 to finish). If you omit this call, the result is undefined. The program can print Hello from thread and a new line, can print just Hello from thread without new line or can print nothing. That's because the main thread can return from the main function before the t1 thread finishes its execution.

In [ ]:
void hello() {
std::cout << "Hello from thread " << std::this_thread::get_id() << std::endl;
}

In [ ]:
std::vector<std::thread> threads;

for(int i = 0; i < 5; ++i){