- Online Community Forums » Programming Questions » Allegro and multitasking

Credits go to A J and ReyBrujo for helping out!
This thread is locked; no one can reply to it. rss feed Print
Allegro and multitasking
Member #4,447
March 2004

I wrote a game using Allegro for graphics and libnet for networking and it seems to have a serious problem with multitasking. When I run in Windows (98) two instances of the program, only the one on foreground seems to work. When both windows are 'unfocused', they work, but they're both updating screen very slowly.
When I run two windows in Linux, they work and communicate without lag, but they're still slow. The graphics are very simple, but it looks like my program is always eating 100% of CPU time.
What can I do to fix the problem?

(I'm setting switch_mode to BACKGROUND/BACKAMNESIA in Allegro, and I put rest(0) in the main game loop, like the manual advises).

January 2001

Allegro always tries to use 100% of CPU. You need to call rest(1); inside your main loop to get a lower CPU usage. As for foreground only working, see set_display_switch_mode.

(Edited: It is rest(1), rest(0) yields CPU, which is something you don't want. As for SWITCH, set it AFTER setting the graphics mode, not before. Also, see Kitty Cat comment).

Mitsuko's last words, Battle Royale

Member #3,025
December 2002

rest(0) is saying to the scheduler, i'll rest if you have something else to do, else i'll continue.

rest(1) says to teh scheduler, i will rest 1 millisecond.

The more you talk, the more AJ is right. - ML

Member #4,447
March 2004

I changed the call to rest(1) and now it works well. Thanks for advice.

Go to: