sem_timedwait()pthreads-win32 errno用法

我在Win32应用程序上使用pthreads-win32作为线程。 我正在使用此处发布的第一个函数计算timespec。

sem_timedwait()的调用似乎在等待指定的ts时间,但是每次完成时我都会得到以下消息:

等待信号量时出错:没有错误

我在这里检查了sem_timedwait.c的文件,它们指定了相同的errno值和返回值。 因此,我不知道为什么它会退出这个错误,并想知道原因。

 #ifdef _WIN32 #define HAVE_STRUCT_TIMESPEC #endif // _WIN32 #include  #include  #include  #include  #include  #include  #include  #include  #include "include.h" // Platform includes #ifdef _WIN32 #include  #include  #else #include  #include  #include  #include  #include  #include  #endif // _WIN32 // ... sem_init(&job_semaphore, 0, 0); // ... // Set wait time relative to current time (semaphore wait time 10s) #ifdef _WIN32 clockGetTime(0, &ts); #else if (clock_gettime(CLOCK_REALTIME, &ts) == -1) { perror("Error getting current time"); } #endif // _WIN32 ts.tv_sec += 10; while ((s = sem_timedwait(&job_semaphore, &ts)) == -1 && errno == EINTR) { // Restart if interrupted by handler continue; } // Timeout or error occurred if (s == -1) { if (errno != ETIMEDOUT) { perror("Error waiting on semaphore"); } } // Job to process else { } 

clockGetTime的代码

 #define HAVE_STRUCT_TIMESPEC #include  #include  int clockGetTime(int clock_filler, struct timespec *spec) { //C-file part __int64 wintime; GetSystemTimeAsFileTime((FILETIME*)&wintime); wintime -= 116444736000000000i64; //1jan1601 to 1jan1970 spec->tv_sec =(time_t) (wintime / 10000000i64); //seconds spec->tv_nsec =(long) (wintime % 10000000i64 * 100); //nano-seconds return 0; }