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

Daniel Schmitt pnambic at unu.nu
Thu Jun 17 20:53:52 UTC 2004


On Thursday 17 June 2004 21:24, Jesse Chappell wrote:
> Chris Cannam wrote on Thu, 17-Jun-2004:
>  > [...]
>  > This is pretty much what we're doing in Rosegarden 0.9.8, but now that
>  > I describe it, I realise I don't know for absolutely sure whether
>  > pthread_cond_signal is itself RT-safe.  More information or better
>  > alternatives are welcome.
>
> 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.

In fact, you don't need to own the mutex to signal or broadcast the condition. 
The one thing you lose by doing that is the guarantee that the 
highest-priority waiter will run immediately, since it will need to reacquire 
the mutex, and some lower-priority thread that was not waiting could be 
holding it. In this situation here, where there is exactly one thread 
waiting, and that thread is the only potential owner of the mutex, that's of 
course not an issue.

Ciao,

Daniel.



More information about the Linux-audio-dev mailing list