LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-17-2008, 03:49 AM   #1
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Rep: Reputation: 32
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?
 
Old 09-17-2008, 05:17 AM   #2
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
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
 
Old 09-17-2008, 05:54 AM   #3
ErV
Senior Member
 
Registered: Mar 2007
Location: Russia
Distribution: Slackware 12.2
Posts: 1,202
Blog Entries: 3

Rep: Reputation: 62
Quote:
Originally Posted by The_Nerd View Post
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.
 
Old 09-18-2008, 10:57 PM   #4
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Original Poster
Rep: Reputation: 32
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Limit System Resources for a Specific Program Revert_To_Saved Linux - Software 3 05-19-2007 11:29 PM
System Resources RySk8er30 Mandriva 2 06-23-2005 06:23 PM
need help compiling program that uses glx SciYro Programming 4 05-20-2005 04:30 PM
System resources... manofwax Linux - Hardware 2 07-23-2004 08:34 PM
having hard time finding FTP server resources e1000 Linux - Networking 2 11-12-2003 11:35 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration