LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

CVI mulithread problems

Computer will freeze and have no response at all when it runs the following codes. Fmt () is probablly the reason for that. Any solutions? Thanks.
 
#include <formatio.h>
#include <dataacq.h>
#include <utility.h>
#include <ansi_c.h>
#include <cvirte.h> 
#include <userint.h>
#include "real time.h"

static int panelHandle, tsqHandle;
int CVICALLBACK WriteQueue (void *functionData);
int threadID, j;
int plotFlag;
volatile int stopFlag;
int main (int argc, char *argv[])
{
 if (InitCVIRTE (0, argv, 0) == 0)
  return -1; /* out of memory */
 if ((panelHandle = LoadPanel (0, "real time.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)
{
 int number, readID, i;
 float dsp;
 char read_string [300];
 switch (event)
  {
  case EVENT_COMMIT:
  
  
   CmtScheduleThreadPoolFunction (DEFAULT_THREAD_POOL_HANDLE, WriteQueue,
                               0, &threadID);
            stopFlag = 0;
            plotFlag = 0;
            j = 0;
           
           
            while (1)
            {
             if (stopFlag == 1) break;
   
             SetCtrlVal (panel, PANEL_Z, (double) j++);
             ProcessSystemEvents ();
            }
   CmtWaitForThreadPoolFunctionCompletion (DEFAULT_THREAD_POOL_HANDLE, threadID, 0);
   CmtReleaseThreadPoolFunctionID (DEFAULT_THREAD_POOL_HANDLE, threadID);
   break;
  }
 return 0;
}
int CVICALLBACK Stop (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 switch (event)
  {
  case EVENT_COMMIT:
  
   stopFlag = 1;
   break;
  }
 return 0;
}
 
int CVICALLBACK WriteQueue (void *functionData)
{
 double dsp;
 char read_string [300];
 
 while (!stopFlag)                                          /*Forzen3: Z can not go beyond 200.*/
{
 
  strcpy (read_string, "123");
  Fmt (&dsp, "%f<%s", read_string);
}
     
 
 return 0;
 
}
 
0 Kudos
Message 1 of 11
(5,533 Views)
I tried running your code, but I could not reproduce the hang. I allowed the numeric control to increment all the way into the 300s without any hang happening.
In your case, does the hang happen on the very first time that the Fmt function executes, or is more erratic than that?
Also, I wouldn't think that it matters what controls are in your panel, but just in case, I'm attaching the .UIR file that I used with your program. You might want to try this one (or attach your own) just to make sure that it isn't a factor.

You seem to be running into a lot of threading issues that the rest of us aren't able to reproduce. I can't explain why this is happening to you, but if I were you, I'd try to run these tests in different computers, always with the same version of CVI (which version are you using?) in order to try to narrow down what factors are contributing to this. It could be affected by a given processor (hyperthreaded, not hyperthreaded?), or it could be affected by some installation anomaly. And of course there could be a bug in CVI, but unless we know more about what factors cause this to happen, or we are able to reproduce it here, we won't be able to make much progress.

Luis
0 Kudos
Message 2 of 11
(5,473 Views)
Thanks. I run the same code in another computer which also has a CVI7.1. The anoying frozen problem is gone. I can tell something is wrong with my CVI.Thank you all.
0 Kudos
Message 3 of 11
(5,461 Views)

I am very frustrated. I reinstalled CVI7.1, however same frozen problem happens to my code. Something is wrong with my windowsXP professional? Thanks.

 

0 Kudos
Message 4 of 11
(5,447 Views)
howdy,

If you want the community to help you solve this problem, you're going to have to provide us more information about your particular situation and what you have done to try to debug the issue.  In the 7 separate threads you have started regarding this issue, you have provided little more than some test code which has run without a hang for everyone who has tried it.  The reason you've had a hard time getting help is because it's almost impossible to have any meaningful guess at your problem without more details.  Because no one else can reproduce the problem, you'll have to do some investigation and report your findings.

You have tried the code on a different computer and noticed that it does not hang, so the problem is related to that particular system.  You have also reinstalled CVI without solving the problem, so it looks like we can rule out a bad installation.  Have you debugged the suspect call to Fmt to determine for sure that the hang happens when executing Fmt?  You can put a breakpoint on the Fmt call and set a pass count so that it breaks only after a certain number of hits.  When the program hangs, is the rest of your system responsive?  Is the CVI environment responsive?  How consistently does the hang occur?  Every time you run the program, or only sometimes?  Does it always hang on the same iteration (same value of the Z counter)?  Can you think of any applicable ways that the problem computer is different from the one in which the program runs properly? Does the system behave strangely (hangs, etc) when running any other programs?

There is no obvious reason for the behavior you are experiencing -- no "magic" answer -- but if you can answer these questions, it might help us come up with some ideas.

Mert A.
National Instruments


0 Kudos
Message 5 of 11
(5,440 Views)
 
Mert,
 
Let me answer your questions. I do not regard this forum smiply as a technical discussion BBS built by some CVI amateurs. Instead, I think it is a place for national instruments (your company) to provide good customer services for your current and potential customers. You asked me why I started 7 different threads to discuss similar questions. That's exactly what I want to ask you why you guys make me repeat the same question again and again? I can't help wondering where your today's post was when I first posted my questions a week ago which nobody in your team cared and replied. I am usually not picky about services provided to me. However, you can evaluate your services by looking at how many 0 replied per day in this forum. Time is life for everybody. I think those people, just like me, are all eagerly waiting for their own answers. I can not imagine if I did not keep posting my question or not call in your company today, how long will my question be kept ignoring. Then what about other customers who are not in US? To many customers of NI, it is absolutely your team's all-time responsibility to make sure every problem is answered timely and correctly.
 
Yes, I can not expect "magic" answers from you, though I can not magicly expect EVERYONE can smoothly run the codes as well. Please read all the discussions about it before you post your suggestion, OK?
 
 
     

0 Kudos
Message 6 of 11
(5,436 Views)

Howdy,

I reviewed all the threads in your multi-threaded approach to getting help on the your multithreading problem.

I tried the code myself on my CVI 8.0.1 (XP Pro SP2, Pentium M Dell D600) and encountered no problems in release or debug. 

It seems almost certain that there are other things wrong with your main PC other than CVI itself -  be it flakey hardware, BIOS, drivers, or other conflicting software.   If you post info on your processor, motherboard and any unusual hardware or software you might have, then it may get the attention of someone who can run a more meaningful test for you.  You should also pare down all other processes running on your PC (i.e. look into services.msc) and see if that helps.

It may be CVI conflicting with something else, and it may be CVI's fault, but if you are the only person with that conflicting component, you can hardly expect us to find it for you.

So, sorry, but I agree with Mert: stick to one thread, give more specifics, and the onus is on you to narrow things down some more.  Posting more specifics will likely trigger ideas and suggestions from others.

Probably not what you wanted to hear, and I know you are frustrated with the problem, but I believe I'm puttting forward a view consistent with most forum users. 

Good luck!

0 Kudos
Message 7 of 11
(5,385 Views)
howdy,

I understand your frustration, and I am sorry that you've felt ignored on this issue.  Many times NI folks will only reply to posts when they have unique knowledge or familarity with the problem, or when no one from the community has already tried to help.  A number of veteran community members had responded with various observations and suggestions, which may be why it was a week before anyone from NI got involved.  In any case, I am sorry you've had a negative experience thus far.  If you do need immediate help, calling our phone support is often a good choice, because you can immediately get in touch with a full time NI support engineer, and they can work with you in realtime.  That's not to say that our online community members aren't a huge depot of experience and expertise to be tapped into. 🙂

I did look back over all the threads and noticed that some of the answers to the questions I posted could be found in them, but this is another good reason to leave all the discussion in one thread.  It makes it much easier to get the full story on a particular issue.

If you do post back some more information, I'd be happy to help.

Mert A.
National Instruments
0 Kudos
Message 8 of 11
(5,366 Views)

Thanks all. I got good and bad news for you all.

Good news: after I install CVI7.1 in another computer and run the same code, the problem was completly gone.

Bad news: I have new problems for my DAQ card when I install CVI7.1 in that new computer. Let me describe the problem and installation procedure as following:

I got a very frustrated problem for my CVI7.1 and traditional DAQ card. I have a brand new computer with windowsXP os. I try to install CVI7.1 and PCI-MIO-16XE-10 traditional DAQ card in it. I first install CVI7.1 and NI driver in the computer. After all the installation is completed, I restart the computer. Then computer found new hardware devices. Following the procedure, I installed the driver for DAQ card. The computer then recognized the PCI-MIO-16XE-10 DAQ card and told me the hardware is ready to use. When I run MAX, I can see PCI-MIO-16XE-10 in the traditional DAQ directory. However, the "test panel" button is grey. Thus I can not access the DAQ card. When I run DAQ related program, the program told me wrong DAQ card or wrong configuration. I thought the driver (DAQ7.3) is not correct. I downloaded 7.4. But the same problem happens. Does anyone know how to solve this problem? Is there any specific installation procedure to install CVI and DAQ card? Thanks for your input.

Thanks all.

 

0 Kudos
Message 9 of 11
(5,324 Views)
howdy,

I'm no DAQ hardware configuration expert, but maybe this link explains why your test panel is disabled (and possibly why you cannot access the board in your program).  Just as an aside, since this is a new issue unrelated to the hang you were experiencing, it would be best to put it in a new thread on the Multifunction DAQ message board.  You'll likely get faster, more certain answers from that audience.

Hope this helps.

Mert A.
National Instruments
0 Kudos
Message 10 of 11
(5,256 Views)