Hi Everyone,
 
I can solve this issue of non wake up of source thread. I had to put in 
sched_yield() in sink thread. So just after codn_broadcast and releasing mutex 
I perform a sched_yield and then go back to top of the do/while as in usb.c 
 
Is this correct behaviour to call for sched_yield as I thought hreads which are 
blocked and ready to run should have been given the chance without the need of 
an explicit sched_yield call.
 
Thanks,
Neeraj


--- On Fri, 1/9/09, Neeraj Tandon <[email protected]> wrote:

From: Neeraj Tandon <[email protected]>
Subject: RE: pthread_cond_wait issue
To: "[email protected]" 
<[email protected]>, "Maupin, Chase" 
<[email protected]>
Date: Friday, January 9, 2009, 8:33 AM







Hi,
 
Thanks for your reply. I see source thread after taking mutex is blocked on 
conditional variables. The sink thread receives data and broadcasts but source 
thread never seems to wake up.  Enclosing the output at the end of mail. This 
output is for when usb device progarm is started and then host sends 512 bytes 
of data. 
 
Thanks,
Neeraj
 
 
./usb -v
DEVNgadgetfs: bound to musb_hdrc driver
AME = musb_hdrc
/dev/gadget/musb_hdrc ep0 configured
serial="rkx1c9uikde4qawp9dhueerb96puddcc8qxptci627n597nasy8fr0jw42znzts"
** Thu Jan 1 14:55:44 1970
gadgetfs: suspended from state 2
SUSPEND
gadgetfs: connected
CONNECT high speed
SETUP 80.06 v0300 i0000 255
SETgadgetfs: configuration #3
UP 80.06 v0302 i0409 255
SETUP 80.06 v0301 i0409 255
SETUP 80.06 v0303 i0409 255
SETUP 80.06 v0303 i0409 255
SETUP 80.06 v0303 i0409 255
SETUP 80.06 v0303 i0409 2
SETUP 80.06 v0303 i0409 128
SETUP 00.09 v0003 i0000 0
CONFIG #3
simple_source_thread start 1083468640 fd 4
blocked on cond
simple_sink_thread start 1091857248 fd 5
broadcast to cond
read ret= 0
Read data from buffer
read unlocking mutex


--- On Fri, 1/9/09, Maupin, Chase <[email protected]> wrote:

From: Maupin, Chase <[email protected]>
Subject: RE: pthread_cond_wait issue
To: "[email protected]" <[email protected]>, 
"[email protected]" 
<[email protected]>
Date: Friday, January 9, 2009, 5:45 AM








Can you include the output from your run so we can see the print messages?  Are 
you sure you are blocked at the pthread_cond_wait and not at the 
pthread_mutex_lock call?
 

Sincerely,
Chase Maupin 
Software Applications 
Catalog DSP Products 
e-mail: [email protected] 
phone: (281) 274-3285 





From: 
davinci-linux-open-source-bounces+chase.maupin=ti....@linux.davincidsp.com 
[mailto:davinci-linux-open-source-bounces+chase.maupin=ti....@linux.davincidsp.com]
 On Behalf Of Neeraj Tandon
Sent: Friday, January 09, 2009 12:34 AM
To: [email protected]
Subject: pthread_cond_wait issue
  





Hi,

 

I have used usb.c ( as posted on Wavinci Wiki page for USB to PCI loopback). I 
modified this by removing some of PCI waitforInterrupt calls and was testing 
with two sink and source threads with pthread_cond_wait and 
pthread_cond_broadcast. Essentially 

 

-  The source thread blocks with a call to pthread_cond_wait

- The sink thread receives data from USB bus and after reading in a buffer 
broadcast to source thread

- The source thread should wake up and write back this data

 

The issue is I do see the call for broadcast to test_cond ( my conditional 
variable) but never see the source thread being woken up by this. Is there 
anything I am doing wrong in this code snippet:

 

WRITE (source thread) 

 

do {

      /* original LinuxThreads cancelation didn't work right

* so test for it explicitly.

*/

pthread_testcancel ();

pthread_mutex_lock(&test_mutex);

if (data_received == 0) {

printf("blocked on cond\n");

ret = pthread_cond_wait(&test_cond, &test_mutex);

printf("write ret = %d\n", ret); 

}

printf("Got data \n");

status = write (source_fd, buffer, USB_BUFSIZE);

data_received = 0; 

pthread_mutex_unlock(&test_mutex);

} while (status >= 0);

 

 

Read (or Sink Thread )

 

do {

/* original LinuxThreads cancelation didn't work right

* so test for it explicitly.

*/

/* pthread_testcancel ();*/

errno = 0;

/* get mutex as we need to protect buffer and data_sent flag */

pthread_mutex_lock(&test_mutex);

/* Read the data from USB into mmap'ed buffer */

status = read (sink_fd, buffer, USB_BUFSIZE);

if (status < 0) {

/* give up mutex */

pthread_mutex_unlock(&test_mutex);

break;

}

data_received=1;

if (data_received == 1) {

/* signal write task */

printf("broadcast to cond\n");

ret = pthread_cond_broadcast(&test_cond);

printf("read ret= %d\n", ret);

}

/* give up mutex */

pthread_mutex_unlock(&test_mutex);

printf("Read data from buffer\n");

printf("read unlocking mutex\n status = %d", status);

} while (status > 0);

 

 

 

 

 

 
 



      
_______________________________________________
Davinci-linux-open-source mailing list
[email protected]
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source

Reply via email to