[asterisk-dev] Sleeping in a channel but in hangup callback

Russell Bryant russell at digium.com
Thu Aug 23 16:31:50 CDT 2007


Paulo Garcia wrote:
> I adopt a code recently of a channel driver. I found inside hangup callback
> a call to sleep(1). Is it the correct way to wait a while inside the hangup
> callback since ast_safe_sleep returns immediately because the hangup flag is
> already set?
> 
> After all, there is no need to wait 1 second there so I changed to a while
> that waits a flag to be set and while is inside the loop I call the usleep
> function waiting 50ms each interaction.

A better way to do what you need would be to use a thread condition.  Look up
how to use pthread conditions.  There are various examples of their usage
throughout our code, as well.

-- 
Russell Bryant
Software Engineer
Digium, Inc.



More information about the asterisk-dev mailing list