LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Using DeclareThreadSafeScalarVar macro

Anybody know how to make this macro work?

I was originally using DefineThreadSafeScalarVar in a single source file and that worked great. The problem is that I need to use those thread safe variables in more than one source file so I went back to the multithreading white paper and it said to use DeclareThreadSafeScalarVar.

Unfortunately, there is zero information on how to use DeclareThreadSafeScalarVar in that paper. It gives plenty of examples for DefineThreadSafeScalarVar but not for the other form. Turns out they take different numbers of parameters, I was able to see that from the utility.h file.

The problem I am having now is that the linker is complaining that none of the accessor functions can be found even though the two source files that use the header are both compiling happily.

I dould move the one function I need the thread safe variables in over to the other file but that would defeat the purpose of trying to keep my common utility functions in one file and my application specific stuff in another.

So does anyone have a handle on this beast?

Any help would be greatly appreciated.
Martin Fredrickson
Test Engineer

Northrop Grumman
Advanced Systems and Products
San Diego, CA 92128
0 Kudos
Message 1 of 6
(4,222 Views)
Hi Martin,

The thread safe variable macros are defined in the CVI utility.h header file. Basically, the DeclareThreadSafeScalarVar macro takes the datatype and name. So, if you want an "int" variable called "Count", you would declare it in your common header as:

DeclareThreadSafeScalarVar(int, Count);

You can also declare this as :
DeclareThreadSafeVar(int, Count);

In ONE of the source files, you would define the variable as:
DefineThreadSafeVar(int, Count);

Note that the Declare macro only declares the functions, and does not define them. So you must use the Define macro in ONE and ONLY ONE source file to provide the definitions of the functions.

Regards,
Mohan
Message 2 of 6
(4,215 Views)
Thanks Mohan, that was the piece of the puzzle I was missing. The white paper on this is not very clear about the usage of the two macros.
Martin Fredrickson
Test Engineer

Northrop Grumman
Advanced Systems and Products
San Diego, CA 92128
0 Kudos
Message 3 of 6
(4,206 Views)
Hello guys, could you help me with this kind of problem regarding the DeclareThreadSafeScalarVar? Error message is: "variables.h" (64,33) Missing parameter type. -I have declared DeclareThreadSafeScalarVar(int, MyVariable); in variables.h -I have defined DefineThreadSafeScalarVar (int, MyVariable, 0); among my global variables declaration in main.c -I have initialised InitializeMyVariable(); at the top of main function and also UninitializeMyVariable(); at the bottom of main. I have included variables.h in three of four source files and obtained error for each file where it is included. (i.e. 3 files with errors in Build Errors window)
0 Kudos
Message 4 of 6
(3,989 Views)
Probably solved out at the meantime, needed to #include to my variables.h (Cost me a tuft of hair)
0 Kudos
Message 5 of 6
(3,986 Views)
*needed to include utility.h
0 Kudos
Message 6 of 6
(3,985 Views)