# CmtSetTSV

int CmtSetTSV (int variableHandle, const void *valuePointer);

## Purpose

Sets the value of the thread safe variable.

If another thread either has the thread safe variable pointer or is currently setting the value of the thread safe variable, this function waits until the other thread has completed its operation.

Do not use this function if the value you are setting depends on the previous value of this thread safe variable. For example, if you want to increment the value of a thread safe integer variable, it is not valid to call CmtGetTSVPtr to get the value, store the value in a local variable, call CmtReleaseTSVPtr to release the pointer, increment the local variable, and then CmtSetTSV to set the value to the value of the local variable. This is not valid because another thread might change the value between your calls to CmtReleaseTSVPtr and CmtSetTSV, thereby invalidating the incremented value of the variable.

It is difficult to program with this function directly. It is easier to program with the functions provided by the DefineThreadSafeScalarVar, DeclareThreadSafeScalarVar, DefineThreadSafeScalarVar, and DeclareThreadSafeScalarVar macros, which are defined in utility.h.

## Parameters

Input
Name | Type | Description
variableHandle | integer | The handle you obtained from CmtNewTSV to identify the thread safe variable.
valuePointer | const void * | A pointer to a variable that contains the needed value.

## Return Value

Name | Type | Description
CmtStatus | integer | 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.