Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7694539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:20:36+00:00 2026-05-31T21:20:36+00:00

This is a sample pgm to check the functionality of Sleep() function.This is a

  • 0

This is a sample pgm to check the functionality of Sleep() function.This is a demo only since iam using this sleep() and clock() functions in my app developement.

  // TestTicks.cpp : Defines the entry point for the console application.
  //

  #include "stdafx.h"
  #include<iostream>
  #include<iomanip>
  #include <Windows.h>

  int _tmain(int argc, _TCHAR* argv[])
  {
    int i, i2;
    i = clock();
    //std::cout<<" \nTime before Sleep() : "<<i;
    Sleep(30000);
    i2 = clock();
    //std::cout<<" \nTime After Sleep() : "<<i2;
    std::cout<<"\n Diff : "<<i2 -i;
    getchar();
      return 0;
  }

in this code i am calculating the time using clock() before and after the sleep function.
Since iam using sleep(30000), the time diff would be atleast 30000.

I have run this prgm many times. and printed output as 30000, 30001, 30002. These are ok. But some times i am getting values like 29999 and 29997.How this possible, since i put 30000 sleep b/w the clock().

Please give me the reason for this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:20:37+00:00Added an answer on May 31, 2026 at 9:20 pm

    According to http://msdn.microsoft.com/en-us/library/windows/desktop/ms686298(v=vs.85).aspx:

    The system clock “ticks” at a constant rate. If dwMilliseconds is less than the resolution of the system clock, the thread may sleep for less than the specified length of time. If dwMilliseconds is greater than one tick but less than two, the wait can be anywhere between one and two ticks, and so on.

    It just means that the Sleep function will never sleep exactly for the amount of time given, but as close as possible given the resolution of the scheduler.

    The same page gives you a method to increase the timer resolution if you really need it.

    There are also high resolution timers that may better fit your needs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this sample MVC project using jQuery grid. There is only one problem
I am using this sample app to make route http://blog.kadirpekel.com/2010/05/30/drawing_routes_onto_mkmapview_using_unofficial_google_maps_directions_api/ It will call the
In this sample code the URL of the app seems to be determined by
This sample app (thoughtsite) for App Engine contains a pom.xml in its trunk: http://code.google.com/p/thoughtsite/source/browse/#svn/trunk
See this sample page . The icon I want to be using is this:
I've this sample code: class A { public function A_A() { /* ... */
I m using this sample for android sdk http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/Compass.html In that sample,the compass is
Using this sample dataset: CREATE TABLE test. test2 (id VARCHAR(7), AA INT, BBB INT,
This sample script: #!/usr/bin/perl -w while (1) { sleep(1); } takes about 264 kB
How can I use this sample Inheritance and Associations with Entity Framework but using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.