LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

concurrent

I am running a chassis with 5 cards inserted in different slots of the chassis.

I need to get the numbers of active slots in the chassis and run the tests on each slot by calling runTest();

The problem I have here is that when calling runTest(), it will run for 20 min (there is a do..while loop inside), this make me to run the test for 20 min times the number of slot.

But what I want is once I get the number of active slots, runTest() on each of them at the same time. How can I start all the runTest() on all the slots at the same time?

I am insisting on the fact that runTest(), will make 20 minutes running. so using the switch...break, seems not to help as when it get to runTest(), it will run for 20 min before switching to the next case.
.
.
.
 for (j=0; j<numbItems; j++)
      
  {
   GetValueFromIndex (panelHandle, PANEL_CPE_SELEC_2, j, &itemValue);
  
     switch (itemValue)

     {
      case 1:
       
        setParams (hub1,slot1); 
        runTest (hub1,slot1); //this runs from 20min
       }
      break;
      
      case 2:
       
        setParams (hub1,slot2); 
        runTest (hub1,slot2);    //this runs from 20min
       }
      break;
      
      case 3:
       
        setParams (hub1,slot3); 
        runTest (hub1,slot3);    //this runs from 20min
       }
      break;
  }
.
.
.

0 Kudos
Message 1 of 6
(3,391 Views)

Multithreading seems a good option in your situation: defining a thread per each device to test could permit to run them with some sort of concurrency.

 

Prerequisite for this is that each unit under test is effectively independent from the other and you can config your chassis to succesfully handle commands for different cards in it. This approach cannot be followed if you have some common resource that cannot be accessed from many concurrent threads at the same time.

 

You will need to define testing procedure so that it can be called more than once, keeping memory and resources for each call independent and separated from other running instances. Additionally, each thread must leave some space for the other concurrent threads to execute.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 6
(3,388 Views)

Hi Roberto,

 

Thank you for replying. Looks like I have to learn a bit more about this multithreading issues. But can you give me any eskeleton that could give me a some good idea?

 

thank you.

0 Kudos
Message 3 of 6
(3,383 Views)

You can find some informations on multithreading in CVI in a document named Multithreading Overview that you should find on your disk: it is normally located in \bin directory in cvi filder, but I seem to remember to have read that in the last release its content has been moved to the online help. You can find it linked in this knowledgebase entry, too.

Another source of informations is this tutorial



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 6
(3,374 Views)

Hi,

I still need some help with creating multithreading.

Here is what I am trying. So as explain before, I need to run test on seperate cards in the same chassis. Each cards occupies 1 slot and they are very independant to each other.
So I have to check all the active slots and run the test on each active slot.

In what I am trying here: I am trying to use multithreading as proposed yesterday, to run this. Please look at this: Looks like I have a problem, when I select only 1 slot (any slot), it runs fine.
but if I select 2 or 3 slots nothing is running. Is this multithreading I am trying right? Is anything missing?

I need some help please, I am trying to finish this today if possible.

Thank you.  Note,this is simplifying version of the all program.

.
.
.

#include <windows.h>
#include <formatio.h>
#include <utility.h>

#include <ansi_c.h>
#include <cvirte.h>  
#include <userint.h>
#include <stdio.h>

  

static int panelHandle;
static int panelHandle_results; 

   
  static int CVICALLBACK ThreadFunction1 (void *functionData);
  static int CVICALLBACK ThreadFunction2 (void *functionData);
  static int CVICALLBACK ThreadFunction3 (void *functionData);

/*/------------------------------------------------------------------------------/*/

int main (int argc, char *argv[])
{
 if (InitCVIRTE (0, argv, 0) == 0)
  return -1; /* out of memory */
 if ((panelHandle = LoadPanel (0, "SystTest.uir", PANEL)) < 0)
  return -1;

 DisplayPanel (panelHandle);
 
 RunUserInterface ();
 
 
 DiscardPanel (panelHandle);
 return 0;
}


 

int CVICALLBACK start (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 
  char buf[100];
 
 int i,j;
 int numIt = 0;

    int threadFunctionId1 = 0;
    int threadFunctionId2 = 0; 
    int threadFunctionId3 = 0;
  
 GetNumListItems (panelHandle, PANEL_CPE_SELEC_2, &numbItems);
 
 for (j=0; j<numbItems; j++)
      
  {

   GetValueFromIndex (panelHandle, PANEL_CPE_SELEC_2, j, &itemValue);
  
   switch (itemValue)
     
     {
      case 1:  

        CmtScheduleThreadPoolFunction (DEFAULT_THREAD_POOL_HANDLE, ThreadFunction1, NULL,&threadFunctionId1);     
      
      break;
      
   
     
      case 2:       
      
        CmtScheduleThreadPoolFunction (DEFAULT_THREAD_POOL_HANDLE, ThreadFunction2, NULL,&threadFunctionId2);
        
      break;
      
      case 3:                       
      
        CmtScheduleThreadPoolFunction (DEFAULT_THREAD_POOL_HANDLE, ThreadFunction3, NULL,&threadFunctionId3);    

      break;
     } 
       
    
      
  }
  
 return 0;
}

 

/* First thread function */
static int CVICALLBACK ThreadFunction1 (void *functionData)
{

        
        setParams (hub1,slot1,port1,slot2); 
        runTest (hub1,slot1,port1, slot2);
        
        
       
    return 0;
}


static int CVICALLBACK ThreadFunction2 (void *functionData)
{

         
       setParams (hub1,slot1,port1,slot3);
       printf("running 1UL"); 
       runTest (hub1,slot1,port1,slot3);
    
    return 0;
}


static int CVICALLBACK ThreadFunction3 (void *functionData)
{
     
 
       setParams (hub1,slot1,port1,slot4);
       runTest (hub1,slot1,port1,slot4);
 
    return 0;
}


 

0 Kudos
Message 5 of 6
(3,361 Views)

I'm afraid I have no actual answer for you...

 

You say that when running a single slot test all works well. Have you tried debugging your code when starting a multiple slot test? Are functions launched correctly? Do you receive any error in CmtScheduleThreadPoolFunction ?

May there be some interlock between functions? Can setParams and RunTest functions be executed more times in parallel? Do threaded functions ever execute?

 

Placing some error checking and some breakpoint in the code may help you in debugging the situation. Start with a breakpoint on the for loop in start callback and check that functions are launched. Next you can place breakpoints in the threaded functions to detect if and how they are executed.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 6 of 6
(3,341 Views)