Fixed some bugs related to pthread_join