How to achive application load balancing in win32 application
-
Hi, My application is having two threads. One is UI thread doing all UI operations. The another thread is doing some heavy work like writing to disk. How I can achive that only when the system have a light load then only the disk writer thread will run and in heavy load cases it will not schedule or scheduled for very low time? How can I know that when system is not heavily loaded and when it is heavily loaded? Is the "Load Balancing" word correct here or it is misleading? Regards, Hemant.
-
Hi, My application is having two threads. One is UI thread doing all UI operations. The another thread is doing some heavy work like writing to disk. How I can achive that only when the system have a light load then only the disk writer thread will run and in heavy load cases it will not schedule or scheduled for very low time? How can I know that when system is not heavily loaded and when it is heavily loaded? Is the "Load Balancing" word correct here or it is misleading? Regards, Hemant.
I don't know that you can perform load-balancing as directly as you want to. However, the Windows API offers the 'CreateThread()' and 'SetThreadPriority()' functions, which allow you to create a thread and set its priority. For example, we can create a thread and set its priority to LOW, in which case the operating system will AUTOMATICALLY schedule the thread for execution in such a way that other, higher priority threads will receive more CPU cycles. This is probably the best way to handle this anyway, as the operating system can allocate CPU cycles more efficiently that you could. In your example, the disk writer thread would be given a low priority. As other tasks are invoked, such as user interface actions, Windows will automatically suspend the desk writer thread and give priority to the user interface. Check out the documentation on 'CreateThread()' and 'setThreadPriority()' for a better description. Scott