The pthread_self function returns the thread ID of the thread in which it is called. This thread ID may be compared with another thread ID using the pthread_equal function.
if (!pthread_equal (pthread_self (), other_thread))
pthread_join (other_thread, NULL);