The main need not to exit before the thread finishes so we have to add another function in main pthead_join () . Here is the edited code
main()
{
thread_t thread;
int tid;
tid=pthread_create(&thread,NULL,write,NULL);
printf("thread1 return %d \n",tid);
pthread_join(thread, NULL);
exit(0);
}