From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

multi threading beginner question

Hi,
 
I don't have any experience with a multithreading, however, the attached file is using a multithreading file and causes me an error.
 
I once given this file (through this board) in order to be able to call my application sequence from the 'Tools' menu.  This sequence seems to call my application in a separate thread.
 
There are 2 files:
     NTN313AA_Tools.seq      this is files is called from the 'Tools' menu
     NTN313AA.seq                 this is the main sequence that I wish to run
 
THE PROBLEM - I load a panel in during the SequenceFileLoad of NTN313AA.seq, use it throughout the application and remove it only during SequenceFileUnload.    I get a -129 error code which means that I can't remove a panel a different thread from the one in which it was created.   Indeed, when I call my sequence (NTN313AA.seq) directly from the 'File' menu, the panel is removed smoothly!!
 
QUESTION - How to fix this problem?
                      Why is it a different thread....?
 
Thank you
Rafi
0 Kudos
Message 1 of 7
(3,652 Views)
The problem you are seeing is that windows have thread affinity (certain operations on them must be done from the thread in which they are created), and the SequenceFileLoad and SequenceFileUnload sequences are not necessarily called from the same thread or even the same thread as your main sequence. What is the behavior you are trying to get with your tool using the load and unload callback? Perhaps there is another way to do it. Also, one alternative to workaround the thread affinity issue is to create a worker thread that does all the calls related to your panel window and in your load and unload callback you can communicate with the worker thread to tell it to create and destroy and do other operations with the window. This can be done with teststand executions, threads, queues, etc. or directly with CVI or whatever development environment you are using.

Hope this helps,
-Doug


0 Kudos
Message 2 of 7
(3,638 Views)

I Dough and Thanks for your answer,

1) To answer you question "What is the behavior you are trying to get with your tool using the load and unload callback? "

     We use the standard User Interface provided by TS3.x, and we use the Tools menu in order to create test menu (list of UUT to run).  I know that if I call my sequence directly it doesn't work, therefore, I'm using the 3 line seq program that does the job.  Still, it's not clear to me why is it necessary to work in more than one thread.  (I was given this seq file and it works fine for me....)

2) Can you give an example of a worker thread that does all the calls related to my panel?  How do I call this panel from the main thread?

 

Thanks

Rafi

0 Kudos
Message 3 of 7
(3,622 Views)
I'm not sure what your tool sequence does, but I think it's likely that it doesn't really need to be using the load and unload callbacks. Try putting the steps in the load callback into the setup section of the mainsequence instead and the steps in the unload callback into the cleanup section.

-Doug

Message Edited by dug9000 on 08-10-2005 10:01 AM

0 Kudos
Message 4 of 7
(3,619 Views)
Just wanted to add that I don't think you will need a multi-threaded solution. If the only thing accessing the panel created in your load and unload callbacks is the sequence you are calling, then you can just move the code out of the load/unload callbacks into the sequence you are calling instead.

Hope that helps,
-Doug
0 Kudos
Message 5 of 7
(3,613 Views)
Hey Dough,
 
It's been a while since your answer and I hope it's ok to get back to it.
 
I have been living with this situation but I'd like solve it.  Your suggestion are not relevant since I want to use the same panel for both SequenceLoad and MainSequence.  Also there are more than one dll involved.  The sequenceFileLoad loads the UIR file into memory. Its handle is saved in TS globals so it can be used by other dlls.  Both the SequenceFileLoad and MainSequence use this uir. The project include several dlls and they all execute LoadPanel (with the handle found in TestStand verialble).  The sequenceFileUnload removes the panel from the memory.   This panel shows all my RS232 activity.
 
The interesing part is that it woks fine when file is loaded from the File menu.  The problem I'm asking about happens only when I use the attached sequence file.
 
 
0 Kudos
Message 6 of 7
(3,479 Views)
Rafi,

The reason why you are having a problem when it's loaded by the tool menu sequence instead of the file menu is the following:

1) Teststand creates threads on an as needed basis and reuses any that were previously created when they are no longer being used.
2) When you load the file from the File menu, no executions are currently running, but then the SequenceFileLoad callback is run (the load callback is an execution). This uses thread 1. Thread 1, being a load callback, must finish before you can run your mainsequence. Therefore by the time you run your mainsequence, thread 1 is no longer in use and can be reused. And, as it happens, when you run your mainsequence you get thread 1 again therefore things work even though there is thread affinity.
3) When you load your file from the tool menu there is already an execution running, the tool menu execution. Since the tool menu execution is already using Thread 1, a new thread, thread 2, must get created and used in order to run your SequenceFileLoad callback. Therefore your SequenceFileLoad callback is run using thread 2 and therefore the thread with which all windows created in your load callback will have affinity is thread 2. But, when you actually get around to running your mainsequence no threads are being used anymore, both the load callback and the tool menu execution have completed, therefore your mainsequence gets run with thread 1 which is not the one that created the windows, therefore the threading requirements for the window handle are not being met and you see the problem that is occurring.

As a solution:

Since you are using the panel in more than one execution and therefore in potentially more than one thread (SequenceLoad and Mainsequence), I recommend you load and unload the panels everytime you start and end an execution rather than trying to share them between the two. If you do this you can also use a file global to share the panel handle rather than a station global which will make your sequence less dependent on things external to the file. Basically load the panel in the setup part of the first sequence of each execution and unload it in the cleanup part of the same sequence.

If there is a reason why this will not work in your situation please explain what you are trying to do in more detail and perhaps I can suggest a better alternative.

-Doug

0 Kudos
Message 7 of 7
(3,465 Views)