usleep resets clock()

This is a discussion on usleep resets clock() within the C Programming forums, part of the General Programming Boards category; Ok i have a program which makes use of clock() function extensively.. now when i add a usleep some int ...

  1. #1
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683

    usleep resets clock()

    Ok i have a program which makes use of clock() function extensively.. now when i add a usleep some int he program I see thatthe clock is reset.. I dont want this to happen.. ..



    any solutions which you guys use.. I know i can use another counter to keep track of time and stuff but is there a simpler solution..



    thanx in advance

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    Mmm, time to guess what OS and compiler you're using?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    oops... g++ on Gentoo
    I think i will add that to my signature...

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    Read the health warning
    NOTES
    The interaction of this function with SIGALRM and other timer functions
    such as sleep(), alarm(), setitimer(), nanosleep() is unspecified.
    This function is obsolete. Use nanosleep(2) or setitimer(2) instead.
    Whilst it does not specifically mention clock(), it does contain the word "unspecified", and the phrase "other timer functions" would be a nice catch for clock()

    Perhaps you should reconsider why you need so many different clocks in your program.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    got rid of clock() and modified code to use localtime.. thanx anyway..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical Error in Clock program
    By SVXX in forum C++ Programming
    Replies: 0
    Last Post: 05-10-2009, 12:12 AM
  2. Outside influences on clock cycles? (clock_t)
    By rsgysel in forum C Programming
    Replies: 4
    Last Post: 01-08-2009, 05:15 PM
  3. Clock Troubles
    By _Nate_ in forum C Programming
    Replies: 22
    Last Post: 06-19-2008, 05:15 AM
  4. clock program
    By bazzano in forum C Programming
    Replies: 3
    Last Post: 03-30-2007, 10:12 PM
  5. world clock
    By nevermind in forum C++ Programming
    Replies: 1
    Last Post: 10-23-2002, 07:45 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21