Hello.
Sleep (x) function make a process sleep during x seconds.
but, how to sleep during milliseconds...
Pls. help me.
Thank you. Regards. 11 47058
On Thu, 09 Dec 2004 11:40:46 +0900, Yeounkun, Oh wrote: Hello.
Sleep (x) function make a process sleep during x seconds.
but, how to sleep during milliseconds...
try 'usleep()'
Not sure if that'll help.
--
PLDaniels - Software - Xamime
Unix systems Internet Development A.B.N. 19 500 721 806
PGP Public Key at http://www.pldaniels.com/gpg-keys.pld
"Yeounkun, Oh" <ra*****@oniontech21.co.kr> writes: Sleep (x) function make a process sleep during x seconds.
but, how to sleep during milliseconds...
There is no sleep() (or Sleep()) function in standard C, though many
systems provide such a function. Many systems probably also provide a
way to sleep for a specified number of milliseconds. You'll need to
ask in a newsgroup that's specific to your system (Windows, Unix,
Linux, whatever).
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Thomas Matthews <Th*************************@sbcglobal.net> wrote: Paul L Daniels wrote: On Thu, 09 Dec 2004 11:40:46 +0900, Yeounkun, Oh wrote:Sleep (x) function make a process sleep during x seconds.
but, how to sleep during milliseconds... try 'usleep()'
Not sure if that'll help.
Which compiler is usleep() found in? I didn't find it in my copy of the C language specification, could you let us know where it is?
Since where off-topic, perhaps you could use: wait() suspend() delay() ms_delay() us_delay()
Don't forget about nanosleep(), which is preferable to usleep()
on UNIX systems...
Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@physik.fu-berlin.de
\__________________________ http://www.toerring.de
"Yeounkun, Oh" Hello.
Sleep (x) function make a process sleep during x seconds.
but, how to sleep during milliseconds...
Pls. help me.
Thank you. Regards.
Jerryrig difftime() found in time.h . If you have a chip made in the last
fifteen years, I think you can do it in standard C with code that would be
nonsensical on a slow machine. I think that is far different than
non-complying or undefined behavior. Google for Chris Torek. MPJ
Merrill & Michele <be********@comcast.net> wrote: "Yeounkun, Oh" > Hello. Sleep (x) function make a process sleep during x seconds.
but, how to sleep during milliseconds...
Pls. help me.
Thank you. Regards.
Jerryrig difftime() found in time.h . If you have a chip made in the last fifteen years, I think you can do it in standard C with code that would be nonsensical on a slow machine. I think that is far different than non-complying or undefined behavior. Google for Chris Torek. MPJ
But there are no guarantees made about the time resolution of difftime()
(on POSIX systems it's not better than second resolution) and the OP
wants milliseconds .(And beside that what he wants seems to be to sleep
and not busy-loop.)
Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@physik.fu-berlin.de
\__________________________ http://www.toerring.de
> Jens: Merrill & Michele"Yeounkun, Oh" > Hello.
Sleep (x) function make a process sleep during x seconds.
but, how to sleep during milliseconds...
Pls. help me.
Thank you. Regards. Jerryrig difftime() found in time.h . If you have a chip made in the
last fifteen years, I think you can do it in standard C with code that would
be nonsensical on a slow machine. I think that is far different than non-complying or undefined behavior. Google for Chris Torek. MPJ
But there are no guarantees made about the time resolution of difftime() (on POSIX systems it's not better than second resolution) and the OP wants milliseconds .(And beside that what he wants seems to be to sleep and not busy-loop.)
To be honest with you, I can't think of a situation makes sense for sleeping
for a matter of milliseconds. Difftime is guaranteed to return a long in
seconds. How does a computer distinguish sleep from a busy loop? MPJ
Merrill & Michele <be********@comcast.net> wrote: Jens: > Merrill & Michele > >"Yeounkun, Oh" >> > Hello. >> >> Sleep (x) function make a process sleep during x seconds. >> >> but, how to sleep during milliseconds... >> >> Pls. help me. >> >> Thank you. Regards. > Jerryrig difftime() found in time.h . If you have a chip made in the last > fifteen years, I think you can do it in standard C with code that would be > nonsensical on a slow machine. I think that is far different than > non-complying or undefined behavior. Google for Chris Torek. MPJ
But there are no guarantees made about the time resolution of difftime() (on POSIX systems it's not better than second resolution) and the OP wants milliseconds .(And beside that what he wants seems to be to sleep and not busy-loop.)
To be honest with you, I can't think of a situation makes sense for sleeping for a matter of milliseconds.
When you're dealing with hardware that requires some timeouts in the
millisecond range it's quite convenient if you don't have to sleep
each time for at least a second;-) And there are also lots of other
cases where a sub-second resolution is important.
Difftime is guaranteed to return a long in seconds.
It returns a double. But that still doesn't guarantee even second
resolution, the standard does not make any statements about the
time resolution of a time_t, it just states that it's an "arith-
metic types capable of representing times".
How does a computer distinguish sleep from a busy loop? MPJ
It's heating the CPU less;-) If you're on a multi-tasking system the
system can schedule other tasks while you're sleeping. Imagine a
situation where you want to e.g. emit a short beep from the speaker
every 5th of a second. With busy-looping that task alone would use
100% CPU time while with a real sleep function it might reduce to a
few percent - so other jobs could be done in between by the machine.
Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@physik.fu-berlin.de
\__________________________ http://www.toerring.de
"Merrill & Michele" <be********@comcast.net> writes:
[...] To be honest with you, I can't think of a situation makes sense for sleeping for a matter of milliseconds. Difftime is guaranteed to return a long in seconds. How does a computer distinguish sleep from a busy loop? MPJ
difftime() returns a double, not a long.
I don't know what you mean by "How does a computer distinguish", but
there's a major difference in a multiprocessing system. A busy loop
causes the current program to consume CPU time; a sleep typically
allows other processes to run. The C standard doesn't deal with
multiprocessing, but a program (even a strictly conforming one) that
executes a busy loop is likely to cause problems.
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
On Fri, 10 Dec 2004 20:18:53 +0000, Jens.Toerring wrote:
.... Difftime is guaranteed to return a long in seconds.
It returns a double. But that still doesn't guarantee even second resolution, the standard does not make any statements about the time resolution of a time_t, it just states that it's an "arith- metic types capable of representing times".
Which is significant because difftime() takes time_t arguments and
therefore its resolution is limited to that of time_t on that
implementation. A double return type provides a simple and useful
interface that can handle finer resolution when it is available.
Lawrence Je***********@physik.fu-berlin.de wrote: Merrill & Michele <be********@comcast.net> wrote: How does a computer distinguish sleep from a busy loop? MPJ
It's heating the CPU less;-) If you're on a multi-tasking system the system can schedule other tasks while you're sleeping. Imagine a situation where you want to e.g. emit a short beep from the speaker every 5th of a second. With busy-looping that task alone would use 100% CPU time while with a real sleep function it might reduce to a few percent - so other jobs could be done in between by the machine.
And let me put on my sysadmin hat once again and add to that that if you
think you'll get away with using a busy-loop on any of my systems,
you're sadly mistaken. Hogging resources is a very good reason to ditch
programs - and programmers.
Richard This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Wolfgang Kaml |
last post by:
Hello All,
I have been working on this for almost a week now and I haven't anything up
my sleeves anymore that I could test in addition or change....
Since I am not sure, if this is a Windows...
|
by: Alexander Erlich |
last post by:
Hello,
I have written a function that returns a random number in dependence of the
time running on the current system. The problem is that initializing two
variables with this function _one...
|
by: Macgyver |
last post by:
Hi all,
does anyone know how to generate a millisecond delay in C, compiling
under Linux? I understand the function sleep() will generate a delay
down to a resolution of one second, but I need...
|
by: Michael Evans |
last post by:
Has anyone come across a way to sleep (suspend execution of current
process while releasing CPU resources in the meantime) for less than a
millisecond in Windows? I know it has been done by third...
|
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...
|
by: --== Alain ==-- |
last post by:
Hi,
under visual C++ exists a function Sleep(millisecond).
What is the equivalent under Visual C++.Net ?
thx,
Alain
|
by: John |
last post by:
The table below shows the execution time for this code snippet as
measured by the unix command `time':
for i in range(1000):
time.sleep(inter)
inter execution time ideal
0 ...
|
by: JoderCoder |
last post by:
When you intruduce a sleep for a certain amount of time, will the whole code sleep during that time? or does it depend on the implementation? could we chose that other threads to be executed even...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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...
| |