02-25-2016 02:32 AM
Hello Tomm,
Thanks for your answer, but i wanna make parallel test thats why i cannot use "CmtScheduleThreadPoolFunctionAdv".
Have you any solution?
Thanks a lot!!!
02-26-2016 12:35 PM
Hi xmouth,
Sorry, I'm not totally clear on your concern about using CmtScheduleThreadPoolFunctionAdv. You should be able to specify a particular thread on which to execute your test, so you should be able to have your three threads executing tests in parallel using this function. Please let me know if there is something I have overlooked!
03-10-2016 04:14 AM
Hello Tommy,
i see many examples using thread pool, i put this code in my StartFunctionCallback:
CmtNewThreadPool(2,&handle);
CmtScheduleThreadPoolFunction (handle, test1ThreadFunction,0, &functionId);
CmtScheduleThreadPoolFunction (handle, test2ThreadFunction, 0, &functionId2);
if (functionId){
CmtWaitForThreadPoolFunctionCompletion (handle, functionId, OPT_TP_PROCESS_EVENTS_WHILE_WAITING); }
if (functionId2){
CmtWaitForThreadPoolFunctionCompletion (handle, functionId2, OPT_TP_PROCESS_EVENTS_WHILE_WAITING);}
if (functionId){
CmtReleaseThreadPoolFunctionID (handle, functionId);}
if (functionId2){
CmtReleaseThreadPoolFunctionID (handle, functionId2);}
CmtDiscardThreadPool (handle);
When i run, i put the two serial number for each DUT, the test start for the two( the first one takes 5sec to finish and the second one takes 10sec), but the two threads ends at the same time (after 10sec).
What should i add to my code to let the test work( example: after 5sec normally the first test ends and the panel appears to put the serial number but it wait until the other thred ends too)
Thaks for your help.
03-11-2016 12:53 PM
Hi xmouth,
Do you see the panel for the new serial number appear five seconds after the tests begin? Or, do the two panels appear at the same time (after 10 seconds)?
Have you tried single-stepping through the code to confirm how long each of these steps are taking? I have attached some documentation below that covers this.
My concern is that your calls to CmtWaitForThreadPoolFunctionCompletion may be causing your application to wait before stepping to the next line. Is this something that you have been seeing?
I still think that you will be better off using CmtScheduleThreadPoolFunctionAdv. It seems to me that your code will be more robust if you create callback functions to execute whenever a test ends. This way, you will not have to predict which order tests may execute in, and you will not have to structure your code to reflect such a prediction. LabWindows/CVI's user interface elements (such as controls and indicators) also operate primarly on callback functions. So, if your test threads are configured to run similarly, they will be more closely aligned to how the rest of your application works.
Stepping through a Program: http://zone.ni.com/reference/en-XX/help/370051Y-01/TOC38.htm
03-14-2016 02:27 AM
Hi Tommy,
when executiong the two pannesl apprears at the same time, i put the serial number for each DUTs the after 10sec the two pannels apprears again.
Also, when i put the serial for the first DUT i still waiting and nothing happen.
Please what should i do ?
Thanks a lot.
03-14-2016 06:45 AM
I followed this thread only marginally but in my opinion you should not put CmtWaitForThreadPoolFunctionCompletion immediately after starting the threads: this vanifies most of the advantages of multithreading. What it happens infact is that even if one thread is faster than the other, the program still waits for the slowest to finish before continuing.
CmtWaitForThreadPoolFunctionCompletion appears normally in a function different from the one that launches the threads, especially if you have multiple threads that run for a different amount of time.
It seems to me that you should rethink your requirements in a multithreading scenario: when is a thread to be started? When the thread does need to prompt the user for data? what are the other threads doing in the meantime? And more specifically: can a therad start and execute while the other is waiting for user input? Can multiple threads ask for user input concurrently?
Suppose a thread has finished and is prompting the user for input: while the user reacts, another thread ends up and shows another input window. The user could be confused with all these windows appearing: how do you intend to handle this situation?
03-14-2016 08:11 AM
Hello Roberto,
Thanks for your answer.
You have described well my problem, to explain more: the program that i wrote calbrate DUT temperature it works well, now i wanna make parallel tests for 2 DUTs at time, i don't know how to manage the threads and let any thread work well and when one finishs what shoud i do?
Have you any solution?
Thanks a lot.
03-14-2016 09:27 AM
Hello xmouth, I do not want to start again discussion this item from scratch with a 3-pages thread already present!
Can you post some sample code? I mean the minimum complete application that mimics what you want to do and exposes the behaviour under discussion. I say so because for example it's not clear where the code you posted in your last posts lies in the program: in a control callback, in a timer callback, in the main... where?
03-14-2016 09:50 AM
Hello Roberto,
This is some of the code:
////////////////////////////Main_Function///////////////////////////////
if (InitCVIRTE (0, argv, 0) == 0)
return (1); /* out of memory */
if ((panelHandle = LoadPanel (0, "tem_vol.uir", PANEL)) < 0)
return -1;
SetPanelPos(panelHandle,30,5);
DisplayPanel (panelHandle);
RunUserInterface ();
}
DiscardPanel (panelHandle);
return 0;
}
/////////////////////Function_Sart_Callback////////////////////////////////////////////
CmtNewThreadPool(2,&handle);
CmtScheduleThreadPoolFunction (handle, test1ThreadFunction,0, &functionId);
CmtScheduleThreadPoolFunction (handle, test2ThreadFunction, 0, &functionId2);
if (functionId){
CmtWaitForThreadPoolFunctionCompletion (handle, functionId, OPT_TP_PROCESS_EVENTS_WHILE_WAITING); }
if (functionId2){
CmtWaitForThreadPoolFunctionCompletion (handle, functionId2, OPT_TP_PROCESS_EVENTS_WHILE_WAITING);}
if (functionId){
CmtReleaseThreadPoolFunctionID (handle, functionId);}
if (functionId2){
CmtReleaseThreadPoolFunctionID (handle, functionId2);}
CmtDiscardThreadPool (handle);
///////////////////////////////Temperature_calibration/////////////////////////////////////////
this code let me to calibrate the temperature
//////////////////////////////Modify NVRAM registres/////////////////////////////////////////
/////////////////////////////////CVICALLBACK test1ThreadFunction//////////////////
temperature nd NVRAM calibration
/////////////////////////////////CVICALLBACK test2ThreadFunction//////////////////
temperature nd NVRAM calibration
////////////////////////////////END//////////////////////////////////////
Thats my code, when the start button is commit i have to test 2DUTs.
I hope that it's clear.
Thanks a lot.
03-14-2016 05:18 PM - edited 03-14-2016 05:20 PM
No, it's not clear. I ask for a complete project and you answer with a few lines of pseudo code
At present I have tons of questions that a working example can answer but I havent it: we are going nowhere this way!
Ok, let's see.
Who is in charge of issuing the popup panel for serial number input and when (at test start, at test end...)?
What is the program supposed to do when test for DUT 1 ends? And when DUT2 terminates?
But basically: it seems you want tests to execute independently, each with its proper timing; if this is true, which is the rationale in waiting for BOTH test to conclude before doing anything else?
One last thing: do not wait for thread completion inside a control callback! This way you cannot handle any other control event until all threads are finished: you cannot even abort tests.