LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Execute function on separate thread (utilize dual core)

I have a two different graphs that can take anywhere from 5 seconds to 1 minute to finish graphing.

 

In total i have a bunch of tabs that show different data.  On a tab, i have a function that graphs data.  After the user clicks 'graph', I would like all the graphing  and calculating to start, while the user can still switch between tabs and look at different stuff.  I know this is all over the forums, but I seem to have trouble using PostDeferredCalltothread or whatever function it is.  It just doesn't run.

 

As a plus, It would be nice to ensure the function gets executed on a different core than the main thread (if dual core or more computer).

 

So please help me with the proper setup of a new thread and execution.

0 Kudos
Message 1 of 6
(4,109 Views)

Hi,

 

How do you know "it does not run"? Did you put any breakpoints or is it because you do not see the graphs get plotted?

 

Before you use PostDeferredCallToThread, you have to start the thread that you will post the work to with CmtScheduleThreadPoolFunction.

 

Make sure that worker thread is still running at the instant you post and it is processing events.

You need to build a loop in the thread function for that.

 

Btw, you also need to make sure the thread that updates a panel should also the one creating it.

Otherwise you may not see the panel and it controls being updated.

 

There is an error code in UI library for that, namely -129.

It may be good idea to check what your UI functions are returning as status?

 

Hope this helps, 

S. Eren BALCI
IMESTEK
0 Kudos
Message 2 of 6
(4,099 Views)
I will try to go through what you mentioned.  Although I am not sure what you mean when you say if the thread is updating a panel, it needs to be the one creating it.  Do you mean creating the panel itself? Because that is done in my main thread.
0 Kudos
Message 3 of 6
(4,084 Views)

Ok so I have gotten my functions to run on a separate thread by looking at the simple.cws example.

 

However, how do I know if it gets executed properly with Dual Core Technology? or does it automatically?  i just wonder because when the graph function executes, I see it uses 50 CPU power.

0 Kudos
Message 4 of 6
(4,069 Views)

I know that it is possible to set the CPU core to be used by a thread in real-time applications written with CVI.

But I am not sure if it possible with Windows applications. I would guess it is handled automatically..

 

About the panels and threads;

You will understand my point if you see the error message in UI library for the error code -129.

Some attributes are clearly not settable from a thread that did not create the panel (a panel is created by the LoadPanel function).

 

For some of my applications, that is the main reason for using PostDeferedCallToThread function.

By using this function, I post the work of updating a panel to the thread that created the panel.

 

Hope this helps, 

S. Eren BALCI
IMESTEK
0 Kudos
Message 5 of 6
(4,057 Views)

It seems like you could just spawn this in another thread without needing to defer it. You can take a look at the CVI multithreading examples. The easiest to get started with is simple.cws which makes use of the CmtScheduleThreadPoolFunction . You could just schedule the task on a new thread each time a user clicks on the tab.

 

 

Update: I just saw your new post. To answer your question, it is normally a good idea to let windows schedule which thread goes to which core for you. Sometimes they can get additional performance by not scheduling to the second CPU. If your computer has two cpu's and windows sees that it can run faster by scheduling different threads on the different CPUs then it will do so. Microsoft has spent years optimizing thread execution, I have seen very few instances where a programmer was more effecient at utilizing cores than windows.


Message Edited by Snowman 6008 on 03-15-2010 01:00 PM
Richard S -- National Instruments -- (former) Applications Engineer -- Data Acquisition with TestStand
0 Kudos
Message 6 of 6
(4,023 Views)