LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Using thread safe variables in a multiple file project

File with delcaration

DefineThreadSafeScalarVar( int, TsvGetMsg, 0)

in file a. I need to access the variable with GetTsvGetMsg(); and SetTsvGetMsg(1); in another file. How do I let the compiler know where those TSV definitions exist. That is, the decalaration was in file a and I want to use the variables in file b. How do I do this?
0 Kudos
Message 1 of 4
(3,729 Views)
Use the DeclareThreadSafeScalarVar macro in a header file and include that header file in the source files that need to reference the variable.

David Rohacek
National Instruments
0 Kudos
Message 2 of 4
(3,729 Views)
The compiler complains of multiply defined...
Then spews out all of the TSV macros
0 Kudos
Message 3 of 4
(3,729 Views)
Hi there,

If you look at the class help for the Thread Safe Variable class (Utility >> Multithreading >> Thread Safe Variable >> Class Help), you'll find a topic on using DefineThreadSafeScalarVar and DeclareThreadSafeScalarVar. According to the class help:
"If you want to use the variable in more than one source file, put the following line in a header file that you include in the source files that use the variable:

DeclareThreadSafeScalarVar (int, MyCounter);"

Do not place the DefineThreadSafeScalarVar in your header file, as this will create multiple definition errors.

Good luck,

Azucena
National Instruments
0 Kudos
Message 4 of 4
(3,729 Views)