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

#define NUM_THREADS 10

volatile size_t count = 0;

void *thread_function(void *thread_id) {
  long tid = (long)thread_id;
  printf("Begin\t%ld\n", tid);
  for (int i = 0; i < 100000; ++i)
    ;
  printf("End\t%ld\n", tid);
  count++;
  pthread_exit(NULL);
}

int main() {
  pthread_t threads[NUM_THREADS];
  long t;

  for (t = 0; t < NUM_THREADS; t++)
    pthread_create(&threads[t], NULL, thread_function, (void *)t);

  void *status;
  pthread_join(threads[0], &status);

  printf("Main thread completed execution\nCount: %zu\n", count);

  return 0;
}
