LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Callback thread does not exit, problem with CNVDisposeData?

Solved!
Go to solution

I have a problem with a callback thread on an RT system. I am working with CVI 8.5 on the pc and the Runtime-engine 9.0 on the RT system.

I am using a client-server-architecture, the client writes data into a 1D network variable, the server is notified via a subscriber connection and releases a callback function. My problem is, this callback function is started in another thread (not the main thread), and is not finished. I have reduced the problem as much as I could, right now the only thing I do in my callback is to dispose of the CNVdata. The problem occurs whenever the callback is released, creating and destroying the subscriber connection without calling the callback does not lead to any problems.

The actual issue about this is that when my program ends, there are still threads left running on the RT system, which may lead to problems later (I have a multi-day-measurement application which crashes always at the same time, so I really need to have this clean).

 

I'll try to post a code snippet to make sure you get what I do (all in the RT main, for simplicity's sake):

 

CNVCreateSubscriber (nameData, dataCallback, NULL, NULL, 3000, 0, &dataSubscriber);

while (!RTIsShuttingDown () && !error)
{
    ProcessSystemEvents();
    Sleep(100);
}

CNVDispose(dataSubscriber);

ProcessSystemEvents();

CloseCVIRTE();

 

My callback basically looks like this:

 

void CVICALLBACK dataCallback (void * handle, CNVData data, void * callbackData)
{
    CNVDisposeData(data);
}

 

When I look at my threads at runtime, I see the callback thread when I am inside, but it still is there afterwards. Also, what is CNVDisposeData supposed to do? The "data" variable keeps its value even after disposing. I can see no change at all.

 

 

I would really appreciate any comments or ideas, I have been trying to fix this for some days now and really don't know what else I could try!

0 Kudos
Message 1 of 5
(3,800 Views)

I just added a trace session to see what happens with my threads, for example like this:

 

TraceUserEvent(2);
error = CNVDisposeData(data);

TraceUserEvent(2);

 

and I see absolutely nothing happening between the two user event flags. I was just wondering if there should be anything happening.

0 Kudos
Message 2 of 5
(3,790 Views)
Solution
Accepted by topic author cholulteca
Yes, for network variables, the callbacks are called on a dedicated worker thread. You do not need the calls to ProcessSystemEvents - the network variable callbacks will still get called. You must call CNVFinish at the end of RTmain in order to make sure the worker thread exits cleanly. If your variable is hosted (configured) on the RT target then the worker thread may continue to run even after calling CNVFinish - I recommend that you host the variable on another machine, say the Windows host.
0 Kudos
Message 3 of 5
(3,779 Views)

Great, with the CNVFinish() the error message has gone, the thread seems to terminate! 🙂 (or at least it doesn't bother me with its state any more 😉 ) Thanks a lot for that hint!

Anyway, about hosting the variables on the PC - this would lead to some problems with multi-client architectures, wouldn't it.

0 Kudos
Message 4 of 5
(3,755 Views)
As long as the hosting machine is available on the network, there should not be any issues with hosting the variable on the Windows host compared to the RT target.
0 Kudos
Message 5 of 5
(3,737 Views)