text: #include <pthread.h>
  #include <stdio.h>
  #include <stdlib.h>
  #include <unistd.h>
  #include <string.h>
  #include <semaphore.h>
  
  #define THREAD_NUM 16
  
  sem_t semaphore;
  
  void* routine(void* args) {
      //enter the access mechanism to the below critical section
      sleep(rand() % 5 + 1); //Critical section
  }
  
  int main(int argc, char *argv[]) {
      pthread_t th[THREAD_NUM];
      int i;
      for (i = 0; i < THREAD_NUM; i++) {
          if (pthread_create(&th[i], NULL, &routine, NULL) != 0) {
              perror("Failed to create thread");
          }
      }
  
      for (i = 0; i < THREAD_NUM; i++) {
          if (pthread_join(th[i], NULL) != 0) {
              perror("Failed to join thread");
          }
      }
      sem_destroy(&semaphore);
      return 0;
  }
  