LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How i can stop a thread function that improves timer lap but that doest use GetUserEvents or RunUserInterface() functions,

I use a table to allocate the functions ID of each function that i schedule on a Thread Pool, and then I make a PostDeferrCall(,ExitThread,) to the thread function I want to stop and the function passed as function "ExitThread" calls CmrExitPoolthreadFunction() to forces it to finish.
The function that i schedule look like that :

void ThreadFunction-Name(...)
{
int variables
safevar *savevarptr;
GetPointToSafeVar();
(make some thinks with the save var)
ReleasePointerToSafeVar();
for(;;) -> infinite loop
{
timer(time); ---> timer for n seconds
switch(variable)
{
case 1:
"make some things";
break;
case 2: "make other stuf"
break;
}
}
//end of threading function
}

how I can stop the infinite loop performed by this threading function?
0 Kudos
Message 1 of 3
(3,131 Views)
The most common method to stop a thread like this would be by changing your infinite loop to check a global flag (i.e. while(runthread) instead of for(;;)). Then, from any other thread you can set the runthread flag to 0 and stop the loop. You would want to declare the runthread variable globally as volatile.

Best Regards,

Chris Matthews
National Instruments
Message 2 of 3
(3,131 Views)
Ok!! I've thought it but it doesn't looks like a "elegance solution".
Is this the only method I can Use?
There's no anyone istead?
0 Kudos
Message 3 of 3
(3,131 Views)