Untitled
Anonymous
plain_text
06/05/2024 3:53 AM
844 B
19
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