[LAD] question about multithreaded externals in Pd

Robin Gareus robin at gareus.org
Sat Oct 2 01:24:26 UTC 2010


On 10/02/10 03:13, Ivica Ico Bukvic wrote:
> Many thanks for the clarification Robin, really appreciate it!
> 
> One more thing I realized, isn't the secondary thread effectively blocking the lock on the main thread because the mutex_lock is placed before the cond call or is this the right way to do it? Namely, should secondary thead have the following structure:
> 
> While loop {
> 	mutex_lock
> 	state cond <--this is where the thread supposedly waits (does this have to be "while" loop or a simple if will do as is the case in my code?)
> 	do something
> 	mutex_unlock
> }
> Thread exit

This looks about right. You need to aquire the lock before calling
pthread_cond_wait() which then release the lock, waits for the condition
to be signaled and acquires the lock again.

Read the first paragraph of `man 3 pthread_cond_wait`

..what could however happen is that pthread_cond_wait() returns with an
error, without acquiring the lock!

HTH,
robin



More information about the Linux-audio-dev mailing list