LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Multithread reloaded in CVI

I used threadpool to generate multithread application. I have following questions about the mechanism:
1. When will the OS do the thread switch between the main thread and second thead?
2. Is the processing time for each thread equal, say 0.01s for each thread?
3. It seems to me if the main thread does not call ProcessSystemEvents (), the second thread will never be processed. If that's true, how can the multithread mechanism guarantee the time critical process in the second thread will not be interrupted or delayed?
 
Thanks.
 
0 Kudos
Message 1 of 2
(2,953 Views)
The operating system (OS) does the thread scheduling, scheduling threads for execution according to the OS's scheduling algorithm, which varies somewhat among the various windows OS versions.  The variation is both in the basic algorithm (generally speaking a form of multi-level feedback queues) but also in the amount of time each thread is allowed to run.   One simple way to view the system is that at any given time, the highest priority thread that is ready to execute will be scheduled.  This means all threads from all applications that are running, not just yours.

You do not need to process system events to cause the OS to schedule a secondary thread. 

This is a moderately complex topic, but generally a Win32 aplication works best if all of the threads within th eprocess are at the "normal" thread priority.  Windows makes assuptions as to how your system is being used (you can use the control panel to tell Windows to emphasize desktop, interactive applications, or server (background, or service) applications).

There's multi-threading tutorial info available on the NI site, and several good books on the topic ISBN 0-201-44234-5, 0-7356-1917-4.  See also the Win32 SDK included with the FSD version of CVI.  It has a full section on processes and threads.  You can get to this on the Microsoft site I believe, even if you don't have the Win32 SDK in CVI.

Menchar



0 Kudos
Message 2 of 2
(2,944 Views)