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
(3,969 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
(3,957 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
(3,948 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
(3,939 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
(3,929 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
(3,908 Views)
Okay I reinstalled the program and still get the same problem. I created a small test program that should have acted like the bigger program to show the problem without a lot of extra code. Unfortunately, the test program worked fine. I guess I'm gonna have to spend a day or two making the test program more like the original or seeing what else may be causing labwindows to close.

Nick
0 Kudos
Message 7 of 9
(3,894 Views)
Another thing may be that the project or workspace got corrupted. You may want to also try just creating a new workspace and project, and then add all the source files and try rebuilding. Just a thought.
Jeremy L.
National Instruments
0 Kudos
Message 8 of 9
(3,882 Views)
Thank you. Great idea. I copied the .c and .h files over to a new folder and made a new workspace and project with those files. It didn't close down Labwindows when I told it to run. I will run a few more tests to make sure but I think you were right and it must have been a corrupt workspace or something like that.

Thank you for the help.

Nick
0 Kudos
Message 9 of 9
(3,877 Views)