Untitled

 avatar
unknown
plain_text
a year ago
631 B
4
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