[ECOS] Help with pthread_cond_timedwait

Graves, Daniel (GE Healthcare) Daniel.Graves@ge.com
Tue May 15 15:34:00 GMT 2012


I've been developing some communication software that needs to wait for a message over a serial port.  I implemented it using pthread_cond_timedwait under Linux using 2.6.34 kernel.  Basically when a message comes over the serial port the pthread_cond_timedwait is signaled.  It waits for 200ms if it is not signaled in time.  This code has worked really well in Linux, but I needed to port it over to eCos.  At that point the exact same code would timeout immediately even though the serial messages were signaling it on time.  The error 360 for ETIMEDOUT was reporting and it was clear that it wasn't waiting long enough.  As a last desperate attempt to get this to work I changed the code to use cyg_cond_timed_wait and cyg_cond_mutex from eCos.  That worked for me and timeouts were no longer occurring.  However, I would like to know what is wrong with pthread_cond_timedwait, because it seems like there is a bug.  But after looking at the code for each function they both basically end up calling Cyg_Condition_Variable's wait methods.  Below is a snippet of the code I'm referring to.  I've searched through this mailing list for any similar topics.  There was one but that one focused on clock_gettime.  Unfortunately I do not know which version of eCos I'm using as I have just joined the project where we're using eCos.  I will try to find that out.

  struct timespec waittime;
  struct timeval abstime;

   //we want to wait 200 msec before declaring timeout
    abstime.tv_usec += 2000000;

    if(abstime.tv_usec >= 1000000)
      abstime.tv_sec += 1;
      abstime.tv_usec = abstime.tv_usec % 1000000;
    waittime.tv_sec = abstime.tv_sec;
    waittime.tv_nsec = abstime.tv_usec*1000;
    int cond_result = pthread_cond_timedwait(&ackcond,&readlock,&waittime);
    if ( cond_result != 0 )
        printf("SerialComm:Failed to set the conditional variable, error = %d\n", cond_result);
        #if DEBUG
        printf("SerialComm:Successfully set conditional variable ackcond\n");



Daniel P Graves

Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

More information about the Ecos-discuss mailing list