//-- cancel the worker thread if (!pthread_equal(worker_cdr_thread, (pthread_t) -1)) { //-- lock the shared ata ast_mutex_lock(&worker_cdr_lock); //-- tell the thread to exit and signal a chance worker_cdr_shutdown = 1; ast_cond_signal(&worker_cdr_cond); //-- release the lock ast_mutex_unlock(&worker_cdr_lock); //-- wait for thread to exit pthread_join(worker_cdr_thread, NULL); worker_cdr_thread = (pthread_t) -1; }