Unix to Windows Porting Dictionary for HPC

Links

Function List

pthread_mutex_trylock


Table of Contents

Unix
Windows
Purpose
Discussion

Unix

header file: pthread.h

int pthread_mutex_trylock(pthread_mutex_t *mutex);

Windows

DWORD WINAPI WaitForSingleObject(
  __in  HANDLE hHandle,
  __in  DWORD dwMilliseconds
);
      

Purpose

The pthread_mutex_trylock function is used to acquire a lock on the specified mutex variable. If the mutex has already been acquired by another thread, the function will return with an EBUSY indication rather than blocking.

Discussion

To achieve the same functionality in the Windows threading model set the Milliseconds parameter to zero for the WaitForSingleObject call. You will receive a WAIT_TIMEOUT indication if the mutex was not signaled when you invoked the function.

blog comments powered by Disqus