Go to Post FRC is about what we collectively make of it. - Tristan Lall [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 05-01-2012, 13:15
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,101
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Win32 Process Scheduling demo


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:

1) an incrementing loop counter, and

2) 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.


 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 19:04.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi