473,396 Members | 1,970 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Sleep?

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
Aug 26 '07 #1
8 3264
Jon Rea wrote:
Just wondering if there is a platform independent, or C++ standard,
function that can 'sleep' a single-threaded app for x milliseconds?
No.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 26 '07 #2
You can use boost::asio::deadline_timer for this purpose. This is
system independent, though you have to use boost package for such
purposes. Just check http://asio.sourceforge.net/boost_as...tuttimer1.html.

Regards,
RM
Aug 26 '07 #3
Reetesh Mukul wrote:
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_as...tuttimer1.html.

Regards,
RM
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 26 '07 #4
Victor Bazarov wrote:
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 <ctimeinclude ?
(only worked with PC's, I'm a beginner :)

Ek.H
Aug 26 '07 #5
Ek.H wrote:
Victor Bazarov wrote:
>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 <ctimeinclude ?
(only worked with PC's, I'm a beginner :)
What would <ctimehave to do with 'sleep'?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 26 '07 #6
Victor Bazarov wrote:
Ek.H wrote:
>Victor Bazarov wrote:
>>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 <ctimeinclude ?
(only worked with PC's, I'm a beginner :)

What would <ctimehave 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 <ctimeon 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
Aug 27 '07 #7
Kai-Uwe Bux wrote:
Victor Bazarov wrote:
>Ek.H wrote:
>>Victor Bazarov wrote:

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 <ctimeinclude ?
(only worked with PC's, I'm a beginner :)

What would <ctimehave 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 <ctimeon 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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 27 '07 #8
Victor Bazarov wrote:
Kai-Uwe Bux wrote:
>Victor Bazarov wrote:
>>Ek.H wrote:
Victor Bazarov wrote:

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 <ctimeinclude ?
(only worked with PC's, I'm a beginner :)

What would <ctimehave 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 <ctimeon 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.
Thanks.

>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"?
Well, I guess expectations are a somewhat subjective matter. My expectations
clearly were not in line with the C standard :-(
Best

Kai-Uwe Bux
Aug 27 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Anks | last post by:
hi I am displaying a digital clock in an applet.I am using Thread.sleep (1000) for counting every second.This works fine some times but some times my clock just slows down or give an...
7
by: Colin Brown | last post by:
Python 2.3.3 Under Windows NT: Negative Int or Real -> sleeps for a long time Under Linux: Returns IOError: Invalid argument I consider both of these unfriendly results and expected the...
5
by: Dave | last post by:
For the life of me, I thought there was a sleep() function in the Standard Library (or something similarly named), but I can't find it. Is it non-existent or, if not, what header is it in? ...
21
by: Alo Sarv | last post by:
Hi From what I have understood from various posts in this newsgroup, writing event loops pretty much comes down to this: while (true) { handleEvents(); sleep(1); // or _sleep() or...
8
by: Cider123 | last post by:
I ran into a situation where my Window Service had to process 100,000+ files, when I first noticed I needed to tweak various routines. Everything runs fine, but here's what I ran into: In the...
9
by: Chris Dunaway | last post by:
According to the docs, calling Thread.Sleep(0) causes the thread to be "suspended to allow other waiting threads to execute." What happens if I call Thread.Sleep(500)? Do other threads not get a...
17
by: OlafMeding | last post by:
Below are 2 files that isolate the problem. Note, both programs hang (stop responding) with hyper-threading turned on (a BIOS setting), but work as expected with hyper-threading turned off. ...
1
by: Matt Brown - identify | last post by:
Hello, I, as well as suspecting many others, am having an issue when I attempt to enter sleep mode in Vista. If any program is connected to the internet (AOL Instant Messenger for instance),...
13
by: Charles Zhang | last post by:
Sleep() function Sleep at lease 1 millisecond, there is a way to make a thread to sleep less than a millisecond? One way I know of is using performance counter which is not really sleep ( loop and...
0
by: Tim Golden | last post by:
Lowell Alleman wrote: Well you've certainly picked a ticklish area to run into problems with ;). First, forget about the threading aspects for the moment. AFAICT the smallest program which...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.