Multi Threading - ProkopHapala/FireCore GitHub Wiki

Multi Threading simple example

#include <string>
#include <iostream>
#include <thread>

using namespace std;

// The function we want to execute on the new thread.
void task1(string msg){
    // ... body
}
void task2(string msg){
    // ... body
}
int main(){
    // Constructs the new thread and runs it. Does not block execution.
    std::thread t1(task1, "Hello");
    std::thread t2(task2, "Hello");
    // Do other things...
    t1.join();  // Makes the main thread wait for the new thread to finish execution, therefore blocks its own execution.
}
⚠️ **GitHub.com Fallback** ⚠️