[linux-audio-dev] Multithreaded programming for a poll model?

Joshua Haberman joshua at reverberate.org
Thu Jun 17 20:16:27 UTC 2004


> Chris Cannam wrote on Thu, 17-Jun-2004:
> If you are using pthread_mutex_trylock() to lock the condition's
> mutex in the RT thread, then you are ok.  If you can't aqcuire
> the lock (hence can't signal) that is usually OK because the other
> thread is already doing work anyway.

I have never understood the purpose of associating a mutex with a
condition variable.  Here is the explanation given in the LinuxThreads man
page:

> A  condition variable must always be associated with a mutex,
> to avoid the race condition where a thread prepares to wait on
> a condition variable and another thread signals the condition
> just before the first thread actually waits on it.

Who cares if that happens?  In this case, the signal should just be
ignored.  Why is this worse than having another thread signal the
condition "well before" the first thread waits on it (instead of "just
before")?  The only rationale I can think of is if the condition value
mechanism is not thread-safe and needs a mutex to prevent it from being
corrupted.

Josh



More information about the Linux-audio-dev mailing list