Creating Threads
Example 1 creates a second thread of execution (
main() is the first thread) and uses that thread to call a global function that prints the message “Hello World!” to the console.
Example 1 – Creating threads
#include <rw/thread/RWThreadFunction.h>
#include <iostream> // 1
using namespace std;
void hello(void) // 2
{
cout << "Hello World!” << endl;
}
int main()
{
RWThreadFunction myThread = RWThreadFunction::make(hello); // 3
myThread.start(); // 4
myThread.join(); // 5
return 0;
}
The following sections take a closer look at some of the key components of this example.