04-22-2015 09:25 AM
Hello,
I want to exit from a thread in a 'for' loop with 1024 repetitions. For example I want to exit in 500th repetition from the thread. I used some functions related with thread. My code is the following:
static int CVICALLBACK GraphLoop (void *functionData) // This is my thread function.
{
FILE *fp;
fp=fopen(fileName,"a");
fprintf(fp,"\n\n Input Number Amplitude Upper Level Lower Level Status\n\n");
for(i=0;i<1024;i++)
{
hpe363xa_queryOutputVolt3631 (vi, 1, &sonuc);
lowerlevel[i]=-3;
upperlevel[i]=3;
amplitude[i] = sonuc;
if (amplitude[i] > upperlevel[i] || amplitude[i] < lowerlevel[i])
{
status[i]='F';
}
else
{
status[i]='P';
}
fprintf(fp," %d %9.5f %9.5f %9.5f %c\n",inputNumber[i], amplitude[i], upperlevel[i], lowerlevel[i], status[i]);
inputNumber[i]=i+1;
plot_handle = PlotXY (testler, TESTLER_GRAPH, inputNumber, amplitude, i+1, VAL_INTEGER, VAL_DOUBLE, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_DOT, 1, VAL_RED);
}
fclose(fp);
return 0;
}
int CVICALLBACK CBBasla (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
if (k==1)
{
k=0;
SetCtrlAttribute (testler, TESTLER_BASLA, ATTR_DISABLE_PANEL_THEME, 1);
CmtNewThreadPool (8, &poolHandle);
CmtScheduleThreadPoolFunction (poolHandle, GraphLoop, NULL, &GraphLoopId);
//CmtWaitForThreadPoolFunctionCompletion (DEFAULT_THREAD_POOL_HANDLE, GraphLoopId, OPT_TP_PROCESS_EVENTS_WHILE_WAITING);
//CmtReleaseThreadPoolFunctionID (DEFAULT_THREAD_POOL_HANDLE, GraphLoopId);
SetCtrlAttribute (testler, TESTLER_BASLA, ATTR_DISABLE_PANEL_THEME, 0);
k=1;
}
else
{
};
break;
case EVENT_RIGHT_CLICK:
break;
}
return 0;
}
int CVICALLBACK CBTestleriKapat (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
CmtWaitForThreadPoolFunctionCompletion (poolHandle,GraphLoopId, 0);
CmtReleaseThreadPoolFunctionID (poolHandle,GraphLoopId);
GraphLoopId = 0;
DiscardPanel(testler);
break;
case EVENT_RIGHT_CLICK:
break;
}
return 0;
}
In this code, what can I use to exit the thread?
04-22-2015 10:22 AM - edited 04-22-2015 10:24 AM
It's not clear to me: