Q:

pthread_exit confusion in for loop

I tried to create 3 threads to do things and repeat for 2 times, I have expected that all of the threads will exit by using pthread_exit(NULL) , but it seems that the output only shows one time and maybe the threads only created one time ...?
I am confused of the usage of pthread_exit(). 
Is it correct that I can destroy the thread by using this one ...? 
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <sched.h>

#define gettid() syscall(__NR_gettid)

void *f1(void *a)
{
    printf("f1\n");
    return NULL;
}

void *f2(void *a)
{
    printf("f2\n");
    return NULL;
}

int main(int argc, char const *argv[])
{
    /* code */
    pthread_t t0,t1,t2; 
    int i ;

    for ( i = 0 ; i < 2 ; i++)
    {
      if (pthread_create(&t0,NULL,&f1,NULL)== -1)
        printf("error 1\n");
      if (pthread_create(&t1,NULL,&f2,NULL)== -1)
        printf("error 2\n");
      if (pthread_create(&t2,NULL,&f1,NULL)== -1)
        printf("error 1\n");

      pthread_join(t0,NULL);
      pthread_join(t1,NULL);
      pthread_join(t2,NULL);

      pthread_exit(NULL);
    }

    return 0; 
}

A:

the output only shows one time and maybe the threads only created one time

The code calls pthread_exit() after the 1st iteration in main()
  for (i = 0 ; i < 2 ; i++)
  {
    ...
    pthread_exit(NULL);
  }

so the thread represented by main() exits and no further iteration are done, so each call to pthread_create() is done once only.
To fix this move the call to pthread_exit() after the for-loop:
  for (i = 0 ; i < 2 ; i++)
  {
    ...
  }

  pthread_exit(NULL);

I am confused of the usage of pthread_exit() .
Is it correct that I can destroy the thread by using this one..? 

pthread_exit() ends the calling thread.
The resources allocated to the ended thread are freed depending whether the thread is detached or attached, the latter is the default.
A thread's resources are freed, for a thread in state ...

attached by calling pthread_join() upon the related pthread-id.
detached upon the thread's termination, so no call to pthread_join() is necessary.

To detach a thread use pthread_detach() on the pthread-id of the thread to be detached.

Also please be aware that for recent implementations of the PThread-API all functions return an error code > 0.
So you should change
  if (pthread_create(&t0, NULL,&f1, NULL)== -1)
    printf("error 1\n");

to be
  if (0 != pthread_create(&t0, NULL,&f1, NULL))
  {
    printf("error 1\n");
  }

or even better
  int result;

  ...

  if (0 != (result = pthread_create(&t0, NULL, &f1, NULL)))
  {
    errno = result;
    perror("pthread_create() failed");
  }

