How can I set a delay for 2ms in c++?

How can I set a delay for 2ms in c++?

Post by Lau » Wed, 25 Jun 2003 12:38:15



I am using a RedHat9.0 and I have tried using the command "Sleep",
"clock" and "time". But they can only provide a delay 10ms (I have
used an oscilloscope to test it). Since I want to excute my program in
console mode, the commands for "TDateTime" can only work in GUI
interface. I world like to ask how can I set a delay for 2ms in c++?
Thank you!!!
 
 
 

How can I set a delay for 2ms in c++?

Post by David Schwart » Wed, 25 Jun 2003 12:47:54



Quote:> I am using a RedHat9.0 and I have tried using the command "Sleep",
> "clock" and "time". But they can only provide a delay 10ms (I have
> used an oscilloscope to test it). Since I want to excute my program in
> console mode, the commands for "TDateTime" can only work in GUI
> interface. I world like to ask how can I set a delay for 2ms in c++?
> Thank you!!!

    You have two choices:

    1) Recompile the kernel with a higher value for HZ

    2) Raise your priority and hold the CPU in a spin loop for 2
milliseconds.

    Both of these options are ugly and not generally recommended. Why do you
think you ened to delay for 2 milliseconds? Most likely, there's another way
to achieve the same effect you're looking for.

    DS

 
 
 

How can I set a delay for 2ms in c++?

Post by Thomas Richte » Wed, 25 Jun 2003 17:33:43


Hi,

Quote:> I am using a RedHat9.0 and I have tried using the command "Sleep",
> "clock" and "time". But they can only provide a delay 10ms (I have
> used an oscilloscope to test it). Since I want to excute my program in
> console mode, the commands for "TDateTime" can only work in GUI
> interface. I world like to ask how can I set a delay for 2ms in c++?

See usleep(3) and select(2).

Greetings,
        Thomas

 
 
 

How can I set a delay for 2ms in c++?

Post by David Schwart » Wed, 25 Jun 2003 18:25:37



Quote:> > I am using a RedHat9.0 and I have tried using the command "Sleep",
> > "clock" and "time". But they can only provide a delay 10ms (I have
> > used an oscilloscope to test it). Since I want to excute my program in
> > console mode, the commands for "TDateTime" can only work in GUI
> > interface. I world like to ask how can I set a delay for 2ms in c++?
> See usleep(3) and select(2).

    That will not help him. These will either delay for 10ms or  no time at
all.

    DS

 
 
 

How can I set a delay for 2ms in c++?

Post by Thomas Richte » Wed, 25 Jun 2003 20:03:23


Hi,

Quote:>> See usleep(3) and select(2).
>     That will not help him. These will either delay for 10ms or  no time at
> all.

Well, maybe it does. See for example nanosleep(2):

       As some applications  require  much  more  precise  pauses
       (e.g.,  in  order to control some time-critical hardware),
       nanosleep is also capable of short high-precision  pauses.
       If  the process is scheduled under a real-time policy like
       SCHED_FIFO or SCHED_RR, then pauses of up to 2 ms will  be
       performed as busy waits with microsecond precision.

Maybe not the perfect solution, but better than nothing.

Greetings,
        Thomas

 
 
 

How can I set a delay for 2ms in c++?

Post by Thomas Borg Salli » Wed, 25 Jun 2003 20:26:29



> I am using a RedHat9.0 and I have tried using the command "Sleep",
> "clock" and "time". But they can only provide a delay 10ms (I have
> used an oscilloscope to test it). Since I want to excute my program in
> console mode, the commands for "TDateTime" can only work in GUI
> interface. I world like to ask how can I set a delay for 2ms in c++?
> Thank you!!!

I suggest that you have a look at ACE
(http://http://www.navicon.dk/mirrors/ace/deuce.doc.wustl.edu/old_dist...).

There are numerous ways of achieving the 2ms sleep you're looking for;
e.g. use ACE_Reactor::schedule_timer(...).

ACE is a bit tricky to learn; but once you're there it pays you back
alot!

Regards,
Thomas.

 
 
 

1. Setting delay (Was changing monitor power down delay on Ultra 5?)


Actually, there are two issues here.

1. powering down the machine is actually considered to be an ADMINISTRATIVE
thing. Running a box that has only you, you may consider that odd, but in
multiuser settings, this makes more sense. So, there is a tool that only
root can use, called dtpower or something.

This is something that also reminded me of another clue:

2. Some monitors automatically power-down if you send them a "black" screen
for X number of minutes. The way to avoid this.. is to avoid having a black
screen. This IS user-configurable, as you mentioned, via the "props" tool.
Please note, however, that this is a change for timeout for
the SCREEN BLANKER. So documentation on this wasn't entirely Sun's fault.
If you waded through the "Users guide" answerbook or something, you may have
found this.

You complained that you can't put in a tweak for every user, in a lab setting.
However, you CAN alter the system-wide window init scripts.

You might try to tweak
/usr/openwin/lib/Xinitrc
which appears  to be the systemwide startup script for openwin, and probably
also used by xinit and/or xdm on solaris.

There used to be a /usr/openwin/lib/xinit dir or something, didn't there?
 Hmmm... AHA!
 /usr/openwin/lib/X11/xdm

has the xdm default stuffs.

"man xdm" would have hinted at the existance of this directory.

--
[trim the no-bots from my address to reply to me by email!]
 --------------------------------------------------
"initiating.. 'getting the hell out of here' maneouver" - Lennier, babylon5

2. Crash on SPARCE 2/75

3. Plug-Ins using C++

4. Boot Puzzler - FreeBSD on 2nd IDE

5. Setting up firewall for dial-ins: How?

6. DB->stat question

7. Getting 1/2ms timmer IRQ's

8. Loading RH 6.1 without using floppies

9. Need Help on setting up getty for dial-ins

10. Setting up Ctrl-Alt-Ins = halt

11. It's not bad canned meat...

12. Alsa sound delay with SuSE 8.0 (4-second delay)

13. It's not bad canned meat...