Portable sleep?

Portable sleep?

Post by Will » Tue, 01 Jul 2003 09:36:07



Hey, semi-OT, but I am trying to keep away from OS-specific code as much as
possible in my little OpenGL projects  (Just using GLUT, and cross platforms
libs, etc.)  Is there an easy way to "sleep" on multiple platforms?

I want my app to have an option to yield CPU time for a brief period, so that
my other apps don't get so sluggish.  As it is, my apps tend to gobble up as
much CPU time as possible, which makes the system a bit less responsive for
windows other than the OGL window.

anyhow, yeah...  Not exactly an on-topic OpenGL question, but I figured you
guys might know an answer...  If there is no cross platform way to sleep, I
guess I'll just start digging through msdn to find the windows way...
------------------
Woooogy
I have to go back in time to pretend to be myself when I tell myself to tell
myself, because I don't remember having been told by myself to tell myself.  I
love temp*mechanics.

 
 
 

Portable sleep?

Post by Will » Tue, 01 Jul 2003 09:59:49


Quote:>Hey, semi-OT, but I am trying to keep away from OS-specific code as much as
>possible in my little OpenGL projects  (Just using GLUT, and cross platforms
>libs, etc.)  Is there an easy way to "sleep" on multiple platforms?

grrrr...  I seem to have answered my own question.

For Linux:
void usleep(unsigned long usec);

and for Windows :
void Sleep(
  DWORD dwMilliseconds
);

oh well, I guess I just have to muss up the code with some conditional
compilation...
------------------
Woooogy
I have to go back in time to pretend to be myself when I tell myself to tell
myself, because I don't remember having been told by myself to tell myself.  I
love temp*mechanics.

 
 
 

Portable sleep?

Post by Greg Chie » Tue, 01 Jul 2003 10:08:19



> Is there an easy way to "sleep" on multiple platforms?

On Un*x, sleep takes seconds and usleep() takes microseconds.  On Win32,
Sleep() takes milliseconds.  Using a macro to switch names and adjust the
parameter is a way to accomplish portability.

Quote:> I want my app to have an option to yield CPU time for a brief period, so
that
> my other apps don't get so sluggish.  As it is, my apps tend to gobble
up as
> much CPU time as possible, which makes the system a bit less responsive
for
> windows other than the OGL window.

A good way to do it is to set the priority your process/thread a tick
below normal.

--
Best Regards,
Greg Chien
e-mail: remove n.o.S.p.a.m.
http://protodesign-inc.com

 
 
 

Portable sleep?

Post by anonymous bimb » Wed, 02 Jul 2003 02:05:52



Quote:> Hey, semi-OT, but I am trying to keep away from OS-specific code as much
as
> possible in my little OpenGL projects  (Just using GLUT, and cross
platforms
> libs, etc.)  Is there an easy way to "sleep" on multiple platforms?

> I want my app to have an option to yield CPU time for a brief period, so
that
> my other apps don't get so sluggish.  As it is, my apps tend to gobble up
as
> much CPU time as possible, which makes the system a bit less responsive
for
> windows other than the OGL window.

The problem isn't that you need to sleep, more that you need to render only
when necessary (ie when something has changed), and consume events only when
one is available. From my limited knowledge of GLUT, I don't think it is
very good at these things. If you try SDL, you'll get an OpenGL window and
better event handling, apparently vxWindows will give you more control too.

As an example, my solar system demo runs nice and smoothly using 5% CPU
under SDL with the fastevents mod.

 
 
 

1. Sleeping Tiger

Gee, anytime I see a subject like yours I *know* I'm in for a treat, and
I wasn't disappointed.

Morbid curiosity, I guess, like a car crash.

2. MTRACE

3. Wake from sleep video problems

4. Texturing triangles....

5. Problem with sleep mode

6. NewTekniques with a legit copy?

7. imac and intuos sleep prob -fix

8. 3d engine and threads?

9. iMac DV freezes when put to sleep.

10. Does PM continue to render in sleep mode?