简体   繁体   English

pthread_cond_timedwait返回错误138

[英]pthread_cond_timedwait returns error 138

I can't find any information on this with Google, so I post here hoping that someone can help... 我在Google上找不到与此相关的任何信息,因此我在这里发布,希望有人可以提供帮助...

My problem is with the Windows pthread function pthread_cond_timedwait() . 我的问题是Windows pthread函数pthread_cond_timedwait() When the indicated time is elapsed, the function should return with value ETIMEDOUT. 经过指定的时间后,该函数应返回值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. 相反,在我的代码中,没有信号通知其条件变量,它返回值138,并且比预期的超时时间更早,有时甚至立即返回。

So my questions are: what is this error 138? 所以我的问题是:错误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. 当前,从不发出条件变量cond_的信号,但是如果我尝试执行此操作,则pthread_cond_timedwait()返回预期的值0。 Even if not shown here, both cond_ and mutex_ are correctly initialised (if I dont't do it, I get a EINVAL error). 即使未在此处显示, cond_mutex_都已正确初始化(如果不这样做,则会收到EINVAL错误)。

Also following the pthread code I can't find this error. 同样在pthread代码之后,我找不到此错误。 I can only find some return errno that could produce it, but I don't know the meaning of the 138. 我只能找到一些可能产生它的return errno ,但我不知道138的含义。

If it can help, I am using Visual Studio 2003 with pthreads win32 v2.9.1. 如果有帮助,我将Visual Studio 2003与pthreads win32 v2.9.1一起使用。

Thanks, 谢谢,

RG RG

Maybe this answer will be helpful for someone. 也许这个答案对某人会有帮助。

I encountered with the same issue. 我遇到了同样的问题。 pthread_cond_timedwait returns error 138 I rummaged all source code of pthread_win32 but didn't find anything similar to error code 138. I downloaded source code of pthread, built it with Visual studio 2008 and... all work nice! pthread_cond_timedwait返回错误138,我翻遍了pthread_win32的所有源代码,但是没有找到与错误代码138类似的东西。我下载了pthread的源代码,用Visual Studio 2008构建了它,...一切正常! :( :(

Cause of such behaviour is that precompilled dll was built with MSVC100, but I build my app with MSVC90. 此类行为的原因是预编译的dll是使用MSVC100生成的,但是我使用MSVC90生成了我的应用程序。 ETIMEDOUT in MSVC100 is 138, but in MSVC90 is 10060. MSVC100中的ETIMEDOUT是138,而MSVC90中的ETIMEDOUT是10060。

Thats all! 就这样! It is Windows, bro! 是Windows,兄弟!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM