*Win32 Process Scheduling demo
“Win32PSdemo.exe” is a simple Win32 console app that may be useful for demonstrating Windows concurrent processing to students, and what happens to the scheduling of a process when it has to compete for CPU resources with other processes.
The app simply runs a ~50Hz infinite loop with a sleep(20) command (block waiting for 20ms) sandwiched between two calls to QueryPerformanceCounter (which reads the Pentium’s high-speed RDTSC clock counter).
The app uses the values from QueryPerformanceCounter to compute the actual elapsed milliseconds for each call to sleep(20).
When you run the app, a small console window will appear with two numbers:
-
an incrementing loop counter, and
-
a number representing the max ms it has taken so far return from the sleep(20) command.
The app contains an array of counters, indexed according to ms from 0 to 500ms. As the app is running, it times each execution of sleep(20) and increments the appropriate counter in the array. Tapping the F1 key will cause the app to display all the non-zero counters in the array, so you can see how well (or poorly) Windows is scheduling the app. The format is ms:count.
If you bring up the Windows Task Manager, you can see that the app uses virtually no system resources, as it is sleeping most of the time.
If there is nothing else running on the system, Windows will run the app fairly consistently at ~50Hz (20ms).
But if you start opening other windows (for example, open your browser and read ChiefDelphi), you will see that the scheduling of the app takes a significant hit.
To exit the app, just close the window.
Source code for the app is provided. It is written in Delpi.
Note: even when the app does not have focus, tapping F1 will cause it to display the counters.