C code pthread semaphore program with 3 threads that prints in sequence

I want to print sequence like 1,2,3,1,2,3…But the below code is not printing in this order. I am not able to understand where I am making mistake in using semaphore. Please help me in understanding the mistake I am making in this code so that I can fix it.

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

#define MAX_NUM 50
sem_t sem1, sem2, sem3;

void *f1(void*)
{
  sem_wait(&sem1);  
  for(int i=1; i<=MAX_NUM; i++)
  {
    printf("\nF1(): %d", 1);
    sem_post(&sem2);         
  }  
}

void* f2(void*)
{
  sem_wait(&sem2);  
  for(int i=1; i<=MAX_NUM; i++)
  {
     printf("\nF2(): %d", 2);
     sem_post(&sem3);
  }
}

void* f3(void*)
{
  sem_wait(&sem3);
  for(int i=1; i<=MAX_NUM; i++)
  {
    printf("\nF3(): %d", 3);    
    sem_post(&sem1);   
 }
}

int main()
{
   pthread_t p1, p2, p3;
   sem_init(&sem1, 0, 1);
   sem_init(&sem2, 0, 1);
   sem_init(&sem3, 0, 1); 

  pthread_create(&p1, NULL, f1,  (void*)NULL);
  pthread_create(&p2, NULL, f2,  (void*)NULL);
  pthread_create(&p3, NULL, f3,  (void*)NULL);  

  pthread_join(p1, NULL);
  pthread_join(p2, NULL);
  pthread_join(p3, NULL);

  return 0;

}

C code pthread semaphore program with 3 threads that prints in sequence