Sleep?

J

Jon Rea

Hello all!

Just wondering if there is a platform independent, or C++ standard,
function that can 'sleep' a single-threaded app for x milliseconds?

Cheers,
Jon
 
V

Victor Bazarov

Jon said:
Just wondering if there is a platform independent, or C++ standard,
function that can 'sleep' a single-threaded app for x milliseconds?

No.

V
 
V

Victor Bazarov

Reetesh said:
You can use boost::asio::deadline_timer for this purpose. This is
system independent,

It's not "system independent". It simply exists on more than one
system. There are systems on which *there is no* timer. Those
systems would still support a C++ implementation, but 'sleep' or
some such functionality just isn't available.
though you have to use boost package for such
purposes. Just check
http://asio.sourceforge.net/boost_asio_0_3_7/libs/asio/doc/tutorial/tuttimer1.html.

Regards,
RM

V
 
E

Ek.H

Victor said:
It's not "system independent". It simply exists on more than one
system. There are systems on which *there is no* timer. Those
systems would still support a C++ implementation, but 'sleep' or
some such functionality just isn't available.

Would these system have no <ctime> include ?
(only worked with PC's, I'm a beginner :)

Ek.H
 
K

Kai-Uwe Bux

Victor said:
What would <ctime> have to do with 'sleep'?

Nothing, but you mentioned the possibility of a C++ implementation on
a system "where there is no timer". That raises the question as to how
one could implement std::clock() from <ctime> on such a system.

I guess, one standard conforming way would be to make clock() return 0 all
the time and have CLOCKS_PER_SEC = 0. However, such an implementation sure
would go against expectations.


Best

Kai-Uwe Bux
 
V

Victor Bazarov

Kai-Uwe Bux said:
Nothing, but you mentioned the possibility of a C++ implementation on
a system "where there is no timer". That raises the question as to how
one could implement std::clock() from <ctime> on such a system.

I guess, one standard conforming way would be to make clock() return
0 all the time and have CLOCKS_PER_SEC = 0.

No, it would be to make 'clock()' return (clock_t)(-1), as the C
Standard says.
However, such an
implementation sure would go against expectations.

Why would it go against expectations? What expectations does one have
when it says "implementation's best approximation"?

V
 
K

Kai-Uwe Bux

Victor said:
No, it would be to make 'clock()' return (clock_t)(-1), as the C
Standard says.
Thanks.



Why would it go against expectations? What expectations does one have
when it says "implementation's best approximation"?

Well, I guess expectations are a somewhat subjective matter. My expectations
clearly were not in line with the C standard :-(


Best

Kai-Uwe Bux
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,781
Messages
2,569,616
Members
45,306
Latest member
TeddyWeath

Latest Threads

Top