473,748 Members | 2,558 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to sleep during millisecond

Hello.

Sleep (x) function make a process sleep during x seconds.

but, how to sleep during milliseconds...

Pls. help me.

Thank you. Regards.
Nov 14 '05 #1
11 47113
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
Nov 14 '05 #2
"Yeounkun, Oh" <ra*****@oniont ech21.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_Keit h) 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.
Nov 14 '05 #3
Paul L Daniels wrote:
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.


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()

You could also use a timer and poll the "done" bit to
see when it is finished. Or you could use an interrupt
system.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.l earn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library

Nov 14 '05 #4
Thomas Matthews <Th************ *************@s bcglobal.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***********@p hysik.fu-berlin.de
\______________ ____________ http://www.toerring.de
Nov 14 '05 #5

"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
Nov 14 '05 #6
Merrill & Michele <be********@com cast.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***********@p hysik.fu-berlin.de
\______________ ____________ http://www.toerring.de
Nov 14 '05 #7
> 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
Nov 14 '05 #8
Merrill & Michele <be********@com cast.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***********@p hysik.fu-berlin.de
\______________ ____________ http://www.toerring.de
Nov 14 '05 #9
"Merrill & Michele" <be********@com cast.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_Keit h) 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.
Nov 14 '05 #10

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

Similar topics

11
3763
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 2003 Server or ADO or ODBC issue, I am posting this on all of the three newsgroups. That's the setup: Windows 2003 Server with IIS and ASP.NET actiavted Access 2002 mdb file (and yes, proper rights are set on TMP paths and path,
4
19397
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 after another_, returns always the same result: function rndnumber () {...} number1 = rndnumber();
8
46271
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 to be able to refine this to milliseconds. Any ideas? Thanks in advance,
3
6233
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 parties such as with the XBO LLADRV project, but I cannot get even enough support from them to enable their software in my project. Ideally, I need something like the unix usleep() function which will do a processor-friendly sleep for some...
9
3486
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 chance to execute during this time? What is the difference between the two? I have code that runs in a loop like this: Dim dResetTime As DateTime = DateTime.Now
4
7776
by: --== Alain ==-- | last post by:
Hi, under visual C++ exists a function Sleep(millisecond). What is the equivalent under Visual C++.Net ? thx, Alain
19
15001
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 0.02 s 0 s 1e-4 4.29 s 0.1 s 1e-3 4.02 s 1 s
1
1629
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 though we introduce a sleep in some other thread? thanks much!
13
5836
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 check again and again and uses CPU time). Thanks Charles Zhang
0
8831
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9555
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9329
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8247
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4607
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4878
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.