Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 28th, 2004, 11:57 AM   #1
mswift
Newbie
 
Join Date: Nov 2004
Posts: 5
Rep Power: 0 mswift is on a distinguished road
I am using a book called Teach yourself C++ Third Edition.
On Exercise #4 on page 38 it calls for a "delay loop" to be used. The purpuse of the exercise is to demonstrate function overloading, something I understand, but what is a delay loop?
mswift is offline   Reply With Quote
Old Nov 28th, 2004, 12:03 PM   #2
Eggbert
Professional Programmer
 
Eggbert's Avatar
 
Join Date: Nov 2004
Posts: 250
Rep Power: 4 Eggbert is on a distinguished road
>what is a delay loop?
for ( int i = 0; i < SOME_BIG_NUMBER; i++ )
 ; // Eat up CPU cycles
This is far from the best way to implement a delay, but it should work for your purposes.
Eggbert is offline   Reply With Quote
Old Nov 28th, 2004, 3:14 PM   #3
kurifu
Expert Programmer
 
kurifu's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia (Canada)
Posts: 784
Rep Power: 5 kurifu is on a distinguished road
Send a message via ICQ to kurifu Send a message via MSN to kurifu
Actually it does not mean that you have to eat up CPU cycles in a delay loop... is just means that there is code in there that is causing a significant delay between iterations, most likely from a sleep command which forces the proecessor to not do anything for a specified period of time in milliseconds.

for(;; )
{
   ...execute some code...
   Sleep( 100 );
}

is a good example of a delay loop. Delay loops are very commonly used in multi-threading and server-client applications, as well as many other applications. Sometimes you can have a process trying to pol for input from a network socket or a local device, the problem is your processor will run a polling loop as fast as it can unless you forece it to slow down... you do this with sleep.

On another interesting not... Sleep( 0 ) is usually a valid statement, and it does not execute a CPU wait for 0 milliseconds, what this usually does is it instructs the operating system to end the timeslice for the process that is running and execute other timeslices for other processes and threads before returning, this is typically a very effective way of managing the polling loop issue.
__________________
Clifford Matthew Roche &lt;geek@cliffordroche.com&gt;
Web Hosting: http://www.crd-hosting.com
Consulting: http://www.crdev-consulting.com
kurifu is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:39 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC