Made pthread_t tid a global variable