LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Benefit of serveral thread pools?

Hello,
 
I'm writing a multi trheaded application. Now I wonder: what's the benefit of creating new thread pools to schedule threads. Is there an advantage, or should I schedule my new threads to run in the default thread pool? Or is it better to create a thread pool for every new thread?
 
Thanks for all tips,
Wim
0 Kudos
Message 1 of 5
(3,555 Views)
Hi Wim,
I guess that the only reason to create new thread pools is that the max number of threads running in the same thread pool is limited (20?).
To be honest, there is another reason: you can assign different priorities to different thread pools. But in this case, you have to use the advanced functions which are more complicated to handle properly. The default thread pool make a lot of things for you.
Regards,


0 Kudos
Message 2 of 5
(3,552 Views)
One reason to create your own thread pool (instead of using the default thread pool) is if you are writing a DLL or an application that will load other CVI user dlls. In this case, the other modules in the process might also be using the default thread pool and this might affect the execution of your thread functions. Creating your own thread pool provides some isolation for your thread functions. Another reason is that you cannot change the properties of the default thread pool but you can fine tune your own thread pool using CmtSetThreadPoolAttribute. By the way, the maximum number of threads in the default thread pool is 2 + (2 * (number of processors)) - i.e. 4 on a single processor machine, 6 on a dual processor, etc.
Message 3 of 5
(3,541 Views)
Here is another scenario where I see an advantage to creating a new thread pool:
  • you continuously acquire chunks of data
  • you need to analyse each chunk as quickly as possible (to detect alarm situations or whatever)
  • the time taken for this analysis can vary widely
  • chunks must be analysed strictly in sequence

A good way to handle this (I believe) is to create a dedicated thread pool having only one thread, and use CmtScheduleThreadPoolFunction() from the acquisition callback to perform the analysis in this single thread. The scheduled tasks will then be queued if necessary, and handled in the correct sequence.

Alternatively, you could call ProcessSystemEvents() in a loop and use PostDeferredCallToThread().

 

Message 4 of 5
(3,522 Views)
The problem with the DEFAULT_THREAD_POOL_HANDLE is that once the Max number(Refer to formula by Mohan) of default threads are reached a thread bottleneck occures.  Say one desires to launch 10 threads at the same time.  If they are launched using default pool, the system will launch only the Max number [only 4 for my machine:(] to start.  All others have to wait until a running thread completes before being launched.
 
 
robskii
Message 5 of 5
(3,518 Views)