Unix to Windows Porting Dictionary for HPC

Links

Function List

pthread_cond_timedwait


Table of Contents

Unix
Windows
Purpose
Discussion

Unix

header file: pthread.h

int pthread_cond_timedwait(pthread_cond_t *cv, pthread_mutex_t *mp, const struct timespec *abstime);

Windows

header file: Windows.h

BOOL WINAPI SleepConditionVariableCS(
  __inout  PCONDITION_VARIABLE ConditionVariable,
  __inout  PCRITICAL_SECTION CriticalSection,
  __in     DWORD dwMilliseconds
);
      

Purpose

The pthread_cond_timedwait causes the calling thread to block on the condition variable until the variable is signaled or until the time of day in abstime has passed. It will atomically release the mutex before blocking and re-acquire it before returning. You cannot infer the state of the condition variable upon the return of the call.

Discussion

The Windows equivalent function is effectively the same as the POSIX version but it has a subtle difference in that the timed wait is not to an absolute time of day but as a time interval listed in milliseconds. Once the time period has elapsed, the call will return if the condition variable has not already been signaled. It is possible that the original POSIX code implemented an interval timed wait by taking the time of day just before the call, added the desired interval and calculated the absolute time of day that would result. This could obviously be simplified in the Windows version.

The return value is zero if the call succeeds. If the timeout occurs the a WAIT_TIMEOUT error code will be returned. If not call GetLastError to get extended error information.

blog comments powered by Disqus