Untitled
unknown
plain_text
2 years ago
631 B
7
Indexable
#include <iostream>
#include <thread>
// Function to be executed by each thread
void threadFunction(int threadID) {
std::cout << "Thread " << threadID << " is running\n";
}
int main() {
const int numThreads = 5;
std::thread threads[numThreads];
// Create multiple threads
for (int i = 0; i < numThreads; ++i) {
threads[i] = std::thread(threadFunction, i);
}
std::cout << "Main thread is running\n";
// Join all the threads with the main thread
for (int i = 0; i < numThreads; ++i) {
threads[i].join();
}
std::cout << "All threads have completed\n";
return 0;
}Editor is loading...
Leave a Comment