LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

YAQ on multithreading

Solved!
Go to solution

I am sorry, but I have yet another question on multithreading and the related functions in the CVI utility library. In the multipanel sample, if one of the chart panels is quit, the function QuitUserInterface is called; this leads to a call to DiscardPanel, hence the chart panel is discarded. In the main thread, the thread pool function ID is freed. But what happens to the thread? No CmtExitThreadPoolThread is called to return the thread to the thread pool... Is it automatically returned 'as available' again to the pool when the thread pool function ID is freed? Or when else?

 

The CVI help says: From within the thread pool thread, call CmtExitThreadPoolThread to ensure that the thread is returned to the pool safely. So why isn't this function called in the sample program?

 

Thanks again,

 

Wolfgang

(I have postponed  converting my program to multithreading for a long time, but now I have made up my mind and as a result I am in the middle of a major confusion...)

0 Kudos
Message 1 of 5
(4,128 Views)

Wolfgang -

 

If you're using Win32, get and read Multithreading Applications in Win32 by Beveridge and Weiner.  ISBN 0-201-44234-5.

 

Showing its age but still good.

 

NI tries to simplify thread usage with their library, but I find that it's easier for me to understand and use the Win32 API threading functions directly.   The CVI library threads ultimately are Win32 threads (or whatever OS you're running on) anyway.

 

The Win32 SDK included with CVI FDS contains quite a bit of info on threading.

 

Multithreading is not for the faint of heart - it can be difficult to create and manage multiple threads and be certain they will behave correctly.  As the developer, you are responsible for coordinating thread access to any shared resources, and for preventing deadlocks / livelocks and other threading pathologies.  On the other hand, lots of people master it, every modern commercial Win32 application is multithreaded, you can prove this to yourself with task manager.

 

Menchar

0 Kudos
Message 2 of 5
(4,115 Views)
hm... have been waiting patiently for an answer on my YAQ... may be someone has an idea concerning the function CmtExitThreadPoolTread? Would be nice 🙂 Thanks 
0 Kudos
Message 3 of 5
(4,061 Views)
Solution
Accepted by topic author Wolfgang

That quote from the help is a bit out of context. That is from the function help for CmtTerminateThreadPoolThread, and it serves to explain a safer alternative to calling CmtTerminateThreadPoolThread.

 

Generally, you should not need to call CmtExitThreadPoolThread. If your thread function returns normally, the thread will be go back into the thread pool, ready for reuse. CmtExitThreadPoolThread is provided to accomodate things like exceptional control flow. You can think of it in the same terms as calling longjmp (which, in fact, is exactly what it does under the hood).

 

Hope that helps.

 

Mert A.

National Instruments

0 Kudos
Message 4 of 5
(4,052 Views)

Hi Mert,

 

Thanks! It is sufficient for me to know that I do not need to call this function. (I have no idea what longjmp is)

 

Wolfgang

0 Kudos
Message 5 of 5
(4,038 Views)