c – How to make two threads execute alternately´╝č

I have two functions f1() and f2() I want f1() and f2() to execute
alternately, without using a loop: Not like this : loop {
f1();
f2(); }

I just want to use thread method My code is below:

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

 void *f1(void *vargp);
 void *f2(void *vargp);

 static sem_t mutex;

 int main(int argc, char **argv) {
     pthread_t tid1, tid2;

     sem_init(&mutex, 0, 1);

     pthread_create(&tid1, NULL, f1, NULL);

     pthread_create(&tid2, NULL, f2, NULL);

     sleep(100);

     return 0;
 }

 void *f1(void *vargp) {
     pthread_detach(pthread_self());

     while (1) {
         sem_wait(&mutex);
         printf("In f1n");
         sleep(1);
         sem_post(&mutex);
     }

     return NULL;
 }

 void *f2(void *vargp) {
     pthread_detach(pthread_self());

     while(1) {
         sem_wait(&mutex);
         printf("In f2n");
         sleep(1);
         sem_post(&mutex);
     }

     return NULL;
 }