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

New Message Reply About this list Date view Thread view Subject view Author view Other groups

Subject: Re: [linux-audio-dev] Multithreaded programming for a poll model?
From: Joshua Haberman (joshua_AT_reverberate.org)
Date: Thu Jun 17 2004 - 23:16:27 EEST


> 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


New Message Reply About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b28 : Thu Jun 17 2004 - 23:11:48 EEST