Multithreading - Kamills-12/2143-OOP GitHub Wiki
Multithreading means running multiple tasks at the same time using separate threads.
You can:
- Run a background task (like loading a file)
- Handle user input while a game loop runs
- Process things faster
In C++, this is done with the <thread>
library.
- Improves performance
- Keeps apps responsive
- Lets you split heavy work into smaller pieces
#include <iostream>
#include <thread>
using namespace std;
void task() {
cout << "Task is running in another thread." << endl;
}
int main() {
thread t(task); // launch thread
t.join(); // wait for it to finish
cout << "Main thread done." << endl;
}