[Asterisk-Dev] pthread_cond_* usage

C. Maj cmaj-SPAM at freedomcorpse.com
Tue May 31 08:04:14 MST 2005


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

The problem is that I've been working on batch processing of
CDR, in combination with CDR handling in a separate thread
to prevent blocking channel hangups on database I/O.  I
wanted to have the CDR batch post either after X records or
Y seconds, whichever comes first.  Using the scheduler, this
doesn't lend itself to a call to poll() with the return
value of ast_sched_wait() because while that blocks for Y
seconds it doesn't allow an early exit after X records.  I
was looking at using a pipe, but then I found the
pthread_cond_* stuff, and it seems perfect for the task.

If this conditional stuff is acceptable, I also wanted to
re-write the manager stuff to add a new thread to handle
pulling events off a queue for distribution to clients.
Instead of manager_event() doing this work directly, it
would simply queue the event and call pthread_cond_signal() to
let the new posting thread wakeup and do the work.

Is there a mechanism in place in * which provides the kind
of functionality I'm describing ?  Or is this a new deal ?

And here's the CDR bug (which could use some more testing):

    http://bugs.digium.com/view.php?id=3883

Thanks,
--Chris


-- 
Chris Maj, Rochester
cmaj_at_freedomcorpse_dot_com
Pronunciation Guide: Maj == May



More information about the asterisk-dev mailing list