Re: pass-thru using audio queues
Re: pass-thru using audio queues
- Subject: Re: pass-thru using audio queues
- From: "Aaron B." <email@hidden>
- Date: Thu, 3 Dec 2009 23:51:00 -0500
On Thu, Dec 3, 2009 at 10:20 PM, William Stewart <email@hidden> wrote:
> You could use the same thread for both the input and output queue, then you
> don't need locks at all
>
> (you just pass in the same run loop to both constructors)
Ah! Now I am starting to see the beauty of run loops.
>>>> (Unfortunately, the
>>>> pthread_mutex_trylock function isn't any help because it seems to
>>>> often give "false negatives," saying it can't acquire a lock even when
>>>> no one else is holding it.)
> I am skeptical - we just pthreads all over the place and have not had these
> issues. You might want to look at the way we support these with the CAGuard
> and CAMutex classes - they provide Try and Lock (build on pthread) and these
> work everywhere we've tried them
I didn't know about these interfaces. I will definitely try them if I
need locks again.
The output below was generated by my code that used the pthread_*
functions directly (it was printed to the console and fflushed after
each line). All locks were acquired within AudioQueue callbacks. No
locks were acquired before the first line of output. Where it says
"... BLOCKING", pthread_mutex_trylock() returned a nonzero value (in
which case my code would immediately called pthread_mutex_lock(), as
per my helper function further below). I know this output isn't very
convincing without seeing and running the code yourself --- if the
behavior is really erroneous and surprising, I may be able to put
together a minimal example for others to look at.
OUTPUT LOCKED BUFFER 3
OUTPUT BLOCKING
OUTPUT LOCKED BUFFER 4
INPUT LOCKED BUFFER 0
INPUT LOCKED BUFFER 1
INPUT RELEASED BUFFER 0
INPUT LOCKED BUFFER 2
OUTPUT RELEASED BUFFER 3
OUTPUT BLOCKING
OUTPUT LOCKED BUFFER 5
INPUT RELEASED BUFFER 1
INPUT LOCKED BUFFER 3
OUTPUT RELEASED BUFFER 4
OUTPUT LOCKED BUFFER 0
OUTPUT RELEASED BUFFER 5
OUTPUT LOCKED BUFFER 1
INPUT RELEASED BUFFER 2
INPUT BLOCKING
INPUT LOCKED BUFFER 4
...
static void mutex_lock_warn (pthread_mutex_t * m, const char * msg) {
if (pthread_mutex_trylock (m) != 0) {
printf ("%s\n", msg);
fflush (stdout);
pthread_mutex_lock (m);
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden