c:c_threads:create_a_thread:create_a_thread_with_a_function_pointer
This is an old revision of the document!
C - C++ Threads - Create a thread - Create a thread with a function pointer
Just pass in the address of a function to the thread constructor.
The thread will start executing the function immediately.
#include <thread> #include <iostream> using namespace std; void FireMissile() { cout << "Firing sidewinder missile " << endl; } int main() { // Create a thread with a function pointer. thread t1(FireMissile); t1.join(); return 0; }
c/c_threads/create_a_thread/create_a_thread_with_a_function_pointer.1614909121.txt.gz · Last modified: 2021/03/05 01:52 by peter