[Asterisk-Dev] pthread_cond_* usage

Kristian Nielsen kn at sifira.dk
Tue May 31 12:30:58 MST 2005


"C. Maj" <cmaj-SPAM at freedomcorpse.com> writes:

> I wanted to query the list for info on any possible negative
> consequences of using the pthread_cond_* functions like
> pthread_cond_timedwait() and pthread_cond_signal().  I just
> found them while reading up on inter-thread communication
> mechanisms, but they seem to be standard and portable
> functions although only used so far in chan_vpb.c

One problem is that it seems there is no way to wait for both a pthread
condition and something else at the same time. The poll() call is better
in that respect since it allows waiting for any number of fds. Hence the
common trick with using an "alert pipe", where the signalling thread
writes dummy data to a non-blocking pipe that the waiting thread is
listening for in poll().

Waiting for multiple fds in poll() is used extensively in various places
in Asterisk. But if a particular event never needs to be waited for
simultaneously with other events, I suppose a pthread condition is fine.

 - Kristian.

-- 
Kristian Nielsen   kn at sifira.dk
Development Manager, Sifira A/S




More information about the asterisk-dev mailing list