I can't find any information on this with Google, so I post here hoping that someone can help...
My problem is with the Windows pthread function pthread_cond_timedwait()
. When the indicated time is elapsed, the function should return with value ETIMEDOUT. Instead in my code, where its conditional variable is not signaled, it returns the value 138 and does it much earlier than the expected timeout, sometimes immediately.
So my questions are: what is this error 138? And why is the timeout not completely elapsed? The code I use for the thread is:
int retcode = 0;
timeb tb;
ftime(&tb);
struct timespec timeout;
timeout.tv_sec = tb.time + 8;
timeout.tv_nsec = tb.millitm * 1000 * 1000;
pthread_mutex_lock(&mutex_);
retcode = pthread_cond_timedwait(&cond_, &mutex_, &timeout);
pthread_mutex_unlock(&mutex_);
if (retcode == ETIMEDOUT)
{
addLog("Timed-out. Sending request...", LOG_DEBUG);
}
else // Something happened
{
std::stringstream ss;
ss << "Thread interrupted (Error " << retcode << ")";
addLog(ss.str().c_str(), LOG_DEBUG);
}
Is there something wrong with my absolute timeout computation?
Only this thread and the calling thread are present. The calling one joins the created one just after its creation and correctly waits until it finishes.
Currently the conditional variable cond_
is never signaled, but if I try to do it, the pthread_cond_timedwait()
returns with value 0 as expected.
Even if not shown here, both cond_
and mutex_
are correctly initialised (if I dont't do it, I get a EINVAL error).
Also following the pthread code I can't find this error. I can only find some return errno
that could produce it, but I don't know the meaning of the 138.
If it can help, I am using Visual Studio 2003 with pthreads win32 v2.9.1.
Thanks,
RG