#include <stdio.h>
#include <pthread.h>

#define THREAD_COUNT 4

void *hello(void *argument) {
    long id = *(long *)argument;
    printf("Hello from worker %ld\n", id);
    return NULL;
}

int main(void) {
    pthread_t workers[THREAD_COUNT];
    long ids[THREAD_COUNT];

    printf("Main thread: starting %d workers\n", THREAD_COUNT);
    for (long t = 0; t < THREAD_COUNT; t++) {
        ids[t] = t;
        pthread_create(&workers[t], NULL, hello, &ids[t]);
    }

    for (int t = 0; t < THREAD_COUNT; t++) {
        pthread_join(workers[t], NULL);
    }
    printf("Main thread: all workers finished\n");
    return 0;
}
