AllExperts > C++ 
Search      
C++
Volunteer
Answers to thousands of questions
 Home · More C++ Questions · Answer Library  · Encyclopedia ·
More C++ Answers
Question Library

Ask a question about C++
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Ralph McArdell
Expertise
I am a software developer with more than 10 years C++ experience and over 20 years experience developing a wide variety of applications for Windows NT/2000/XP, UNIX, Linux and other platforms. I can help with basic to advanced C++, C (although I do not write just-C much if at all these days so maybe ask in the C section about purely C matters), software development and many platform specific and system development problems.

Experience
My career started in the mid 1980s working as a batch process operator for the now defunct Inner London Education Authority, working on Prime mini computers. I then moved into the role of Programmer / Analyst, also on the Primes, then into technical support and finally into the micro computing section, using a variety of 16 and 8 bit machines. Following the demise of the ILEA I worked for a small company, now gone, called Hodos. I worked on a part task train simulator using C and the Intel DVI (Digital Video Interactive) - the hardware based predecessor to Indeo. Other projects included a CGI based train simulator (different goals to the first), and various other projects in C and Visual Basic (er, version 1 that is). When Hodos went into receivership I went freelance and finally managed to start working in C++. I initially had contracts working on train simulators (surprise) and multimedia - I worked on many of the Dorling Kindersley CD-ROM titles and wrote the screensaver games for the Wallace and Gromit Cracking Animator CD. My more recent contracts have been more traditionally IT based, working predominately in C++ on MS Windows NT, 2000. XP, Linux and UN*X. These projects have had wide ranging additional skill sets including system analysis and design, databases and SQL in various guises, C#, client server and remoting, cross porting applications between platforms and various client development processes. I have an interest in the development of the C++ core language and libraries and try to keep up with at least some of the papers on the ISO C++ Standard Committee site at http://www.open-std.org/jtc1/sc22/wg21/.

 
   

You are here:  Experts > Computing/Technology > C/C++ > C++ > C++ delay a loop or funtion for paticular time delay

C++ - C++ delay a loop or funtion for paticular time delay



Follow-Ups to Answer from Expert Ralph McArdell


Pedro wrote at 2006-07-19 15:40:07
Incredible...

Sleep and sleep exist on both unix and Windows OS... So there is no need to reinvent the wheel and to do marvelous things shuch as while(tick() - nStart < nDelay) which consume about 100% cpu cycles during the wait... totally unuseful...

Sleep or sleep is a passive wait call which release your thread/process until the delay has been reached.

On Win32, Sleep is not very accurate when you begin to play with durations around 10-20ms (windows is not real-time os certified), but I have noticed in many projects that WaitForSingleObject(hObject, nDuration) (where hObject is an unused HANDLE (NULL for example) and nDuration is a timeout in ms, is really more accurate than Sleep (or WaitForMultipleObjects...).


Ralpho wrote at 2007-02-28 19:28:03
I wrote this answer. If you had read it all you would have noticed that I make this very point.

However functions such as sleep, nanosleep, Sleep and WaitForSingleObject are _not_ part of C++ they are part of the operating system APIs.

Hence I start with the basic and standard then move onto better ways. I accept the point about WaitForSingleObject, however in many cases such accuracy is not required. This is especially true for those just starting to find out that there is a big wide world of operating system API functions out there.



Add to this Answer   Ask a Question


 
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.