#include <iostream>
#include <thread>
// Function to be executed by each thread
void threadFunction(int threadID) {
std::cout << "Thread " << threadID << " is running." << std::endl;
}
int main() {
// Number of threads to create
const int numThreads = 3;
// Create an array to hold thread objects
std::thread threads[numThreads];
// Launch threads using a loop
for (int i = 0; i < numThreads; ++i) {
// Pass the thread function and its arguments to the thread constructor
threads[i] = std::thread(threadFunction, i);
}
// Join threads to the main thread
for (int i = 0; i < numThreads; ++i) {
threads[i].join();
}
std::cout << "All threads have completed." << std::endl;
return 0;
}