LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Thread Problem

I am writing a program (in labwindows cvi 7.1) that starts multiple threads for recieving data. When everything was in one .c file, it worked perfectly. I need to split it into mulitple .c and .h files due to the size. When I do that, I seem to have problems with my threads.

Specifically, when I put the:
int CVICALLBACK DataAcqThreadGPS (void *functionData);
into my header file it gives an error:
"Interface.h"(204,17) syntax error; found 'identifier' expecting ';'.

And if I just put the
int CVICALLBACK DataAcqThreadGPS (void *functionData);
into the .c file, no errors but when I try to run the program everything shuts down. I mean the program and labwindows itself.

What am I doing wrong? It works all in one file but apparently something needs to change when you start adding header files.


Thanks,
Nick
0 Kudos
Message 1 of 9
(4,114 Views)
Hi Nick.

The clue is in this line:

"Interface.h"(204,17) syntax error; found 'identifier' expecting ';'.

- specifically, the character position (17).

At this point, the compiler does not know what "CVICALLBACK" means (effectively it means "__cdecl"), so it "thinks" that you are declaring a variable named CVICALLBACK, and expects to see ";" (or "," and further identifiers).

To fix this, you need to:

#include < cvidef.h >

(either directly or indirectly) in your "Interface.h" file.

Further, each source file where this function is called needs to #include the header containing the prototype. The default return type (int) is assumed, but without the "__cdecl", the compiler won't include stack cleanup code with the call, leading to the crash.

The approach I use for my larger projects is to place all non-UI function prototypes in a single .h file, and #include this file in each .c file.

Regards,
Colin.
0 Kudos
Message 2 of 9
(4,102 Views)
Thank you for your help. I added the
#include to my .h file

That got rid of the error. It sill closed labwindows upon trying to run.
I then switched:
int CVICALLBACK DataAcqThreadGPS (void *functionData3);
to
int __cdecl DataAcqThreadGPS (void *functionData3);

It still closed labwindows upon trying to run.

Nick
0 Kudos
Message 3 of 9
(4,093 Views)
What error are you getting before CVI closes? If it is a runtime error, you may have to debug your application to see what line it's failing on and if it's doing it repeatedly in the same function call. This should give you a hint as to what's causing the crash. If it's crashing while you are trying to build the application, then something unusual may be going on with the compiler. Hope this helps!
Jeremy L.
National Instruments
0 Kudos
Message 4 of 9
(4,084 Views)
There is no error that shows up before it closes or after it closes. It just shuts itself down. Maybe I'll try reinstalling cause I even try clicking on debug and that shuts it down too.

Nick
0 Kudos
Message 5 of 9
(4,074 Views)
If reinstalling doesn't work, can you post a sample project that exhibits this behavior so we can test it on another machine to determine if it's truly just this system or the project? Thanks!
Jeremy L.
National Instruments
0 Kudos
Message 6 of 9
(4,053 Views)