Help with pthread_cond_timedwait
Graves, Daniel (GE Healthcare <Daniel.Graves <at> ge.com>
2012-05-15 15:33:48 GMT
Hello,
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;
.....
gettimeofday(&abstime,NULL);
//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;
(Continue reading)