Re: [LAD] question about multithreaded externals in Pd

From: Robin Gareus <robin@email-addr-hidden>
Date: Sat Oct 02 2010 - 04:24:26 EEST

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
_______________________________________________
Linux-audio-dev mailing list
Linux-audio-dev@email-addr-hidden
http://lists.linuxaudio.org/listinfo/linux-audio-dev
Received on Sat Oct 2 08:15:01 2010

This archive was generated by hypermail 2.1.8 : Sat Oct 02 2010 - 08:15:01 EEST