LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   GLX Program in a hard loop and using all system resources (https://www.linuxquestions.org/questions/programming-9/glx-program-in-a-hard-loop-and-using-all-system-resources-670450/)

The_Nerd 09-17-2008 03:49 AM

GLX Program in a hard loop and using all system resources
 
Hello, I am writing a program using XLib and GLX (OpenGL) on Linux to draw in the root window. All it is is a slideshow for my desktop. The program launches, grabs the root window, and goes to town... but I have one small problem.

The loop in my main is causing my CPU to be used 100%. This isn't good for a desktop "beautifier"... Is there a way to tell the loop to calm down? Maybe like the Sleep(0) in windows?

dmail 09-17-2008 05:17 AM

What you are seeing is normal behaviour for a graphics app as this is what is normally wanted ie run as fast as you can. Have a look at usleep or sleep
http://opengroup.org/onlinepubs/0079...sh/usleep.html
http://opengroup.org/onlinepubs/0079...xsh/sleep.html

ErV 09-17-2008 05:54 AM

Quote:

Originally Posted by The_Nerd (Post 3282861)
The loop in my main is causing my CPU to be used 100%. This isn't good for a desktop "beautifier"... Is there a way to tell the loop to calm down? Maybe like the Sleep(0) in windows?

Use "sleep" or similar function to limit number of frames-per-second to 15 or below. This will drop CPU usage.

The_Nerd 09-18-2008 10:57 PM

Thanks for your help guys. I got it working great with nanosleep... however, nanosleep seams more like it is sleeping for milliseconds than for nanoseconds. Oh well, I tweaked my program to work with what ever it is doing.


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