Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [4.2] Windows multitasking CPU usage

This thread is locked; no one can reply to it. rss feed Print
[4.2] Windows multitasking CPU usage
Gerwin Broers
Member #3,681
July 2003
avatar

I have two programs made with Allegro v4.2 (windows).
When running these programs windowed, then switching out and load up another application to make a screenshot or something else: the system gets really slow. The system I tested this on is Windows 2000 SP5 on a single core Athlon 3000+. The programs are compiled with both MSVC6 and Dev-C.

For the second program, which is a development tool for a game, it is important to me that users can multitask it comfortably. The programs are mostly in a loop just polling the keyboard.

I read about a CPU idle patch for allegro 4.4 in this forum, but did not find any reference to it in the latest allegro 4 changelog, so did not try v4.4 yet.

There are task switch in and switch out hook functions, but since I don't know how to idle, what should I make the program do at task switch out?

Main Project: HeroQuest. And Other Stuff

Audric
Member #907
January 2001

If your program currently takes 100% (of one) CPU at all times, it lacks
rest(number_milliseconds)

Gerwin Broers
Member #3,681
July 2003
avatar

wow, I just added "else rest(10);" at the end of the key polling and all multitasking troubles have vanished, while the program itself seems as snappy as before.

I should have learned about this years ago.

Thanks a lot Audric.

Main Project: HeroQuest. And Other Stuff

Thomas Fjellstrom
Member #476
June 2000
avatar

resting is not the best option. Look at the "Making use of the ticks" section of the Wiki's Timers Article.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Audric
Member #907
January 2001

That section uses rest() too, were you thinking of the semaphore technique ? It saves less CPU, it would gain timing precision in theory (*) but I think the game is his "HeroQuest", a turn-based board game with little animation except the mouse cursor... The difference would be invisible.

When it comes to CPU saving / optimization, my guidelines are
Priority 1) be sure to rest(>0) when "nothing to do"
Priority 2) don't redraw the screen if nothing has changed
Priority 3) ...don't bother anymore :)

(*) not on Windows because of its 10ms timer granularity

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Audric said:

(*) not on Windows because of its 10ms timer granularity

I think this is a badly perpetuated myth - I've never seen rest take more than an additional millisecond or so of overhead to return. (That's on Vista, and maybe XP as well).

Elias
Member #358
May 2000

I guess maybe Windows 98 and also Linux systems from that time (it's a kernel setting there I think) could use 10ms. I have never seen it either though.

[edit:] rest(10) instead of rest(1) will use 10ms of course.

--
"Either help out or stop whining" - Evert

Gerwin Broers
Member #3,681
July 2003
avatar

This question was for TFDtool:
http://combatace.com/topic/68667-alternate-tfd-terrain-tilemap-editorviewer/
But I will also put it in heroquest when I find the time.

I adjusted it to:
if (keypressed())
{
//key polling
}
else rest(5);

Main Project: HeroQuest. And Other Stuff

Go to: