Untitled

mail@pastecode.io avatar
unknown
plain_text
10 days ago
631 B
1
Indexable
Never
#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;
}
Leave a Comment