LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Multithreading blocking problem

In thread "A" I call MatLab through active X.
It takes a very long time for MatLab to finish the function I called from my CVI thread and therefore I want this process to run in the background and stop if I start an other thread "B" that has higher priority than thread "A" (and also needs MatLab). The problem is that the execution of thread "A" can not continue until the MatLab function has finished so I can't solve it with the Sleep function for example. Is there a possibility to from thread "B" tell thread "A" to pause/block the (MatLab-) execution so that it is possible to give the processor time to threads with higher priority? Thanks!
0 Kudos
Message 1 of 4
(2,752 Views)
You can lower that thread "A"'s priority from thread "B", or you can terminate thread "A" from thread "B" (not recommended), but you can't block it until it finishes that MatLab function.

Best Regards,

Chris Matthews
National Instruments
0 Kudos
Message 2 of 4
(2,752 Views)
I think your problems lies within your matlab function, since this waits
until completion, you can't really do anything other than Chris Mathews
solution of 'killing' that thread. This is probably not a good idea because
you don't know what effect it will leave the matlab calls/data in.

Imagine that the matlab function has a delay 10 seconds in it. When Thread
A calls it, there is no way it will finish that function call before the 10
seconds is up. Unless the matlab function has a method of terminating its
10 second loop, you have no choice but to wait.

If the matlab function has an execution time that is relational to the
amount of processing time it is allocated by the OS, then you could change
its priority level to a lower level, and call thread B. (or call
thread B,
but give it a higher priority). But, seeing as you call an activeX control,
this might infact be another process/thread that already has a fixed
priority, seeing as thread A is really waiting inside the ActiveX call, it
is this thread/process that will be required to be changed, not A or B.

Does thread B call a different function (ActiveX) to thread A ?

"stina" wrote in message
news:50650000000800000006700000-1042324653000@exchange.ni.com...
> In thread "A" I call MatLab through active X.
> It takes a very long time for MatLab to finish the function I called
> from my CVI thread and therefore I want this process to run in the
> background and stop if I start an other thread "B" that has higher
> priority than thread "A" (and also needs MatLab). The problem is that
> the execution of thread "A" can not continue until the MatLab function
> has finished so I can't solve it with the Sleep function for example.
> Is there a possibility to from thread "B" tell thre
ad "A" to
> pause/block the (MatLab-) execution so that it is possible to give the
> processor time to threads with higher priority? Thanks!
Message 3 of 4
(2,752 Views)
Thank you for your answer! I think you are right about, that it is MatLab's priority that has to be changed, I don't know how I could do that from CVI though. The other problem is that thread B also needs MatLab (but not the same functions). I guess it's hard to change the priority just when thread A calls MatLab.
0 Kudos
Message 4 of 4
(2,752 Views)