LabWindows/CVI

Table of Contents
  • LabWindows/CVI Fundamentals
  • Creating Applications
  • Distributing Applications
  • Library Reference
  • Programmer Reference
  • Hardware Information

CmtTryToGetLock

int CmtTryToGetLock (CmtThreadLockHandle lockHandle, int *obtainedLock);

Purpose

Tries to get ownership of the thread lock.

When you finish using the thread lock, you must release the lock by calling CmtReleaseLock from the same thread that called CmtTryToGetLock.

Only one thread can get ownership of the thread lock at a time. If a thread requests the lock while another thread owns the lock, CmtTryToGetLock returns immediately without obtaining the lock.

You can call CmtTryToGetLock from the same thread more than once, but you must call CmtReleaseLock once for each time that you successfully obtained the lock.

Parameters

Input
Name Type Description
lockHandle CmtThreadLockHandle The handle you obtained from CmtNewLock to identify the thread lock.
Output
Name Type Description
obtainedLock int Returns 1 if you obtain the lock.

Returns 0 if you fail to obtain the lock.

Return Value

Name Type Description
cmtStatus int The CmtStatus code that the function call returns. This function returns 0 to indicate success and negative values to indicate failure. Pass the CmtStatus code to CmtGetErrorMessage to get a description of the error code.

Additional Information

Library: Utility Library

Include file: utility.h

LabWindows/CVI compatibility: LabWindows/CVI 8.5 and later

Example

Refer to utility\threading\ThreadLockTimeout\ThreadLockTimeout.cws for an example of using the CmtTryToGetLock function.

Log in to get a better experience