Skip to content

Threads

#include <thread>

The std::thread object takes a function pointer1 as argument in its constructor.
As soon as the thread object is created, it is executed.

void hi () {
    std::cout << "hi" << std::endl;
}

int main () {
    std::thread thread_1(hi);  //hi() is immediately fired off
}

References


  1. Read more about function pointers