pthread_cond_timedwait() in Windows
pthread_cond_timedwait() in Windows
我尝试在我的代码中实现pthread
功能。不幸的是,我无法正确实现功能pthread_cond_timedwait()
。 在Linux中,一切正常。但在 Windows 中,此函数始终返回错误代码 10060。这是我的简单代码:
#include <fstream>
#include <Windows.h>
#define HAVE_STRUCT_TIMESPEC
#include <pthread.h>
int main()
{
int rcTimedwait = 0;
struct timespec timeout;
pthread_mutex_t mutex;
pthread_cond_t condVar;
pthread_mutex_init(&mutex, NULL);
pthread_cond_init(&condVar, NULL);
timeout.tv_sec = 1;
timeout.tv_nsec = 0;
SetLastError(0);
errno = 0;
pthread_mutex_lock(&mutex);
rcTimedwait = pthread_cond_timedwait(&condVar, &mutex, &timeout);
printf("rcTimedwait = %dn", rcTimedwait);
printf("errno = %d GetLastError = %dn", errno, GetLastError());
printf("tv_sec = %d tv_nsec = %dn", timeout.tv_sec, timeout.tv_nsec);
pthread_mutex_unlock(&mutex);
pthread_cond_destroy(&condVar);
pthread_mutex_destroy(&mutex);
return 0;
}
和输出:
rcTimedwait = 10060
errno = 0 GetLastError = 0
tv_sec = 1 tv_nsec = 0
提前感谢您的任何帮助,并为我的英语感到抱歉
pthread_cond_timedwait()
返回了 10060,这看起来像 WSAETIMEDOUT 的值。我很惊讶该函数没有按预期返回 ETIMEDOUT。
无论如何,这是一个超时,这并不奇怪,因为在您的示例中,没有其他线程来指示条件变量。
相关文章:
- std::async from std::async in windows xp
- 如何在 google test in windows 中管理断言
- 在Windows Visual Studio中实现<netinet/in.h>
- C++ - 程序接收信号SIGSEGV,分段错误.In msvcrt!memcpy () (C:\Windows\S
- 使用 new in C++(在 Windows 上)分配大于 2GB 的单个对象
- pthread_cond_timedwait() in Windows
- TLS with http_listener in Microsoft cpprestsdk on Windows
- Windows 10 环境中的"This version of XAudio2 is available only in Windows 8"错误
- QT c++ "Windows.h no such a file or dictionary in main.ccp"
- QB,如何在Windows上配置.h.in文件
- No FileIO in Windows Phone?
- OLEUnInitialize() in windows 7
- Sleep() in Windows 消息循环
- Cython in Windows 64 with GSL
- gethostname() in windows
- Windows Runtime activatable class in Windows 10
- openCV in Windows mobile
- ShellExecute in Windows Embedded
- pthread_mutex_trylock? pthreads in Windows
- Issue with eclipse juno for c,c++ in windows