# Original code /* Read monitor thread function. */ static void *do_chanreads(void *pvt) { ………………….. // Using trylock here to prevent deadlock when channel is hungup // (ast_hangup() immediately gets lock) if (p->owner && (ast_mutex_trylock(&p->owner->lock)==0) ) { ast_queue_frame(p->owner, fr); ast_mutex_unlock(&p->owner->lock); if (option_verbose > 4) { short * data = (short*)readbuf; ast_verbose("Read channel %s (codec=%d) %d %d\n", p->dev, fmt, data[0], data[1] ); } …………….. ------------------------------------------------------------------------- # Patch /* Stop record */ p->stopreads = 1; + sleep(1); //to prevent immediately lock if( p->readthread ) pthread_join(p->readthread, NULL); @@ -1455,7 +1456,8 @@ // Using trylock here to prevent deadlock when channel is hungup // (ast_hangup() immediately gets lock) - if (p->owner && (ast_mutex_trylock(&p->owner->lock)==0) ) { + if (p->owner && !p->stopreads ) { + ast_mutex_lock(&p->owner->lock); ast_queue_frame(p->owner, fr); ast_mutex_unlock(&p->owner->lock); if (option_verbose > 4) {