thread group c++

#include <iostream>
#include <thread>
#include <vector>
#include <algorithm>

void worker_function(int id) {
    std::cout << "Thread " << id << " is executing." << std::endl;
}

int main() {
    const int num_threads = 5;
    std::vector<std::thread> threads;

    for (int i = 0; i < num_threads; ++i) {
        threads.push_back(std::thread(worker_function, i));
    }

    std::cout << "Main thread is executing." << std::endl;

    // Joining threads to ensure main thread waits for all threads to finish
    std::for_each(threads.begin(), threads.end(), std::mem_fn(&std::thread::join));

    return 0;
}