473,882 Members | 1,566 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to write a time delay function?

Hello,
I want to write a time delay function like "Timedelay(floa t time_lenth){}".
When execute it, it will delay some seconds as long as "time_lenth "
indicating. Could you help on how to write such a function?

----------------
lovely newsgroup
----------------
Sep 8 '06 #1
24 16147

Chen Shusheng wrote:
Hello,
I want to write a time delay function like "Timedelay(floa t time_lenth){}".
When execute it, it will delay some seconds as long as "time_lenth "
indicating. Could you help on how to write such a function?

----------------
lovely newsgroup
----------------
usleep() is one way to do it ( whereas it is supported ).

Sep 8 '06 #2
Chen Shusheng said:
Hello,
I want to write a time delay function like "Timedelay(floa t
time_lenth){}".
When execute it, it will delay some seconds as long as "time_lenth "
indicating. Could you help on how to write such a function?
#include <time.h>

void Timedelay(float time_lenth)
{
time_t start = time(NULL);
time_t end;
do
{
end = time(NULL);
} while(difftime( end, start) < time_lenth);
}

(Presumably 'lenth' is meaningful somewhere in the world.)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Sep 8 '06 #3
Thanks.
"Richard Heathfield" <in*****@invali d.invalid>
??????:XY****** **************@ bt.com...
Chen Shusheng said:
>Hello,
I want to write a time delay function like "Timedelay(floa t
time_lenth){}".
When execute it, it will delay some seconds as long as "time_lenth "
indicating. Could you help on how to write such a function?

#include <time.h>

void Timedelay(float time_lenth)
{
time_t start = time(NULL);
time_t end;
do
{
end = time(NULL);
} while(difftime( end, start) < time_lenth);
}

(Presumably 'lenth' is meaningful somewhere in the world.)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)

Sep 8 '06 #4
Richard Heathfield <in*****@invali d.invalidwrites :
Chen Shusheng said:
> I want to write a time delay function like "Timedelay(floa t
time_lenth){}".
When execute it, it will delay some seconds as long as "time_lenth "
indicating. Could you help on how to write such a function?

#include <time.h>

void Timedelay(float time_lenth)
{
time_t start = time(NULL);
time_t end;
do
{
end = time(NULL);
} while(difftime( end, start) < time_lenth);
}

(Presumably 'lenth' is meaningful somewhere in the world.)
That's a portable way to do it, but not a good way to do it. By
calling time() repeatedly in a loop, it's likely (on a
multi-processing system) to gobble lots of CPU time.

Most systems provide a way to do this kind of thing, though standard C
doesn't.

--
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.
Sep 8 '06 #5
"Chen Shusheng" <cs*****@gmail. comwrote:
I want to write a time delay function like "Timedelay(floa t time_lenth){}".
When execute it, it will delay some seconds as long as "time_lenth "
indicating. Could you help on how to write such a function?
You use a system-specific function, which you can ask for in a
system-specific newsgroup.
Alternatively, you _could_ use a busy-loop, and be killed by your
systems manager for tying up the system.

Richard
Sep 8 '06 #6

"Richard Bos" <rl*@hoekstra-uitgeverij.nl写 入消息新闻:45** *************** @news.xs4all.nl ...
"Chen Shusheng" <cs*****@gmail. comwrote:
> I want to write a time delay function like "Timedelay(floa t
time_lenth){}" .
When execute it, it will delay some seconds as long as "time_lenth "
indicating. Could you help on how to write such a function?

You use a system-specific function, which you can ask for in a
system-specific newsgroup.
Alternatively, you _could_ use a busy-loop, and be killed by your
systems manager for tying up the system.

Richard
My system is windowsXP. Where should I post to get the answer? Could you pls
indicate?
Sep 8 '06 #7
Keith Thompson said:

<snip>
That's a portable way to do it, but not a good way to do it.
He didn't ask for a good way to do it. By posting in comp.lang.c, he asked
for a comp.lang.c way to do it.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Sep 8 '06 #8
Chen Shusheng wrote:
"Richard Bos" <rl*@hoekstra-uitgeverij.nl写 入消息新闻:45** *************** @news.xs4all.nl ...
>"Chen Shusheng" <cs*****@gmail. comwrote:
>> I want to write a time delay function like "Timedelay(floa t
time_lenth){} ".
When execute it, it will delay some seconds as long as "time_lenth "
indicating. Could you help on how to write such a function?
You use a system-specific function, which you can ask for in a
system-specific newsgroup.
Alternativel y, you _could_ use a busy-loop, and be killed by your
systems manager for tying up the system.

Richard

My system is windowsXP. Where should I post to get the answer? Could you pls
indicate?
Start at http://msdn.microsoft.com/ . If you need a newsgroup - query
your news server for windows programming groups.
Sep 8 '06 #9
"Nils O. Sel錽dal" wrote:
Chen Shusheng wrote:
>"Richard Bos" <rl*@hoekstra-uitgeverij.nl>
写入消息新闻:4 5************** ***@news.xs4all .nl...
>>"Chen Shusheng" <cs*****@gmail. comwrote:

I want to write a time delay function like "Timedelay(floa t
time_lenth){ }".
When execute it, it will delay some seconds as long as
"time_lent h"
indicating . Could you help on how to write such a function?
You use a system-specific function, which you can ask for in a
system-specific newsgroup.
Alternatively , you _could_ use a busy-loop, and be killed by your
systems manager for tying up the system.

Richard

My system is windowsXP. Where should I post to get the answer?
Could
you pls indicate?

Start at http://msdn.microsoft.com/ . If you need a newsgroup -
query
your news server for windows programming groups.
The things to look for are SetTimer and KillTimer... These are
Windows-API and thus off topic here. Just to provide a reference for
future lookups. If you need higher resolution use the
multimedia-timer. It's also described there.

HTH
--
Johannes
You can have it:
Quick, Accurate, Inexpensive.
Pick two.
Sep 8 '06 #10

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

Similar topics

1
14876
by: gmv | last post by:
Hi, I am doing a project and i would like to know if anyone can please tell me how to write a delay or wait function in c++ which works asynchronously with other programs. Thank you, GMV
2
3686
by: notregister | last post by:
I'm to delay my program for some limited time...i try using the following codes but it doesn't work, how do i do a time delay??? 'Extracted from the main function Timer11.Start() Do tCC = timeCount Loop Until timeCount > 10000
0
1159
by: jayasakthi | last post by:
when we freeze the columns of a table in jsp, there is a time delay in scrolling the page. when we unlock the columns the time delay is not there. is there any solution for decreasing the time delay without locking the columns.
1
3695
by: klmishraa79 | last post by:
i want to know how i can put a time delay between two command execution...i.e. after first command of programm the second command should execute after some fixed delay......i want to use time delay other than sleep or timer....is it there any direct delay command like it is in c and c+...looking for ur suggestions.....thanks
9
2275
by: Martin Wells | last post by:
I'm doing an embedded systems project and I'm programming it as fully- portable C89 (except of course for setting the pin values). I need to put delays in the program, in the vicinity of 250 ms. (They don't need to be exact). Does C have a built-in method of putting in delays? If not, I was thinking of defining a macro called "FLOPS" (i.e. floating-point operations per second) and then doing something like:
1
7013
by: maul581 | last post by:
I know the delay( ) function of Turbo C and used it in my project. By this function we can give intermediate delay in execution from 1 millisecond to 9999 millisecond. My main question is "Is it possible to get delay less than 1 millisecond in Turbo C"? If by changin any header file (e.g. dos.h) or by creating my own "delay" function, at any way Can I get delay less than 1 millisecond? If in C it is not possible than please suggest me any...
3
22439
Ali Rizwan
by: Ali Rizwan | last post by:
Hello all, I want to put delay in my loops as we use in c/c++.. Is there any delay function in vb6 which put delay between any code??? Thanx >> ALI <<
2
5123
by: Rahina | last post by:
I am working in Dreamweaver 8, and I have created a simple form: http://www.realmofmystery.com/app.html This is a free website I am doing for some friends, so nothing fancy. And, I learned web design before all the CGI and PHP stuff got big, so I prefer to do things simply. The form worked fine, emails the results like perfect, but it refused to redirect the page to the confirmation. I thought I could add an onClick to the submit button,...
8
4242
by: Craig Williamson | last post by:
I'm trying to write a time delay loop in Borland C 3.1 (for legacy code) which has an accuracy of about 0.1ms. This change is due to a hardware change and the software is now running too fast to take proper readings. I have been using delay(1) in the past but it does not have the accuracy that I need for this situation. Does anyone know of a useful C function which can be used to create the time delay? If anyone could help that would...
0
9777
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
11108
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...
0
10725
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10403
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9557
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梡lanning, coding, testing, and deployment梬ithout 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...
0
5781
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...
1
4601
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
4198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3226
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.