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 8308029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:40:32+00:00 2026-06-08T18:40:32+00:00

CLOCK_MONOTONIC does not seem available, so clock_gettime is out. I’ve read in some places

  • 0

CLOCK_MONOTONIC does not seem available, so clock_gettime is out.

I’ve read in some places that mach_absolute_time() might be the right way to go, but after reading that it was a ‘cpu dependent value’, it instantly made me wonder if it is using rtdsc underneath. Thus, the value could drift over time even if it is monotonic. Also, issues with thread affinity could result in meaningfully different results from calling the function (making it not monotonic across all cores).

Of course, that is just speculation. Does anyone know how mach_absolute_time actually works? I’m actually looking for a replacement to clock_gettime(CLOCK_MONOTONIC… or something like it for OSX. No matter what the clock source is, I expect at least millisecond precision and millisecond accuracy.

I’d just like to understand what clocks are available, which clocks are monotonic, if certain clocks drift, have thread affinity issues, aren’t supported on all Mac hardware, or take a ‘super high’ number of cpu cycles to execute.

Here are the links I was able to find about this topic (some are already dead links and not findable on archive.org):

https://developer.apple.com/library/mac/#qa/qa1398/_index.html
http://www.wand.net.nz/~smr26/wordpress/2009/01/19/monotonic-time-in-mac-os-x/
http://www.meandmark.com/timing.pdf

Thanks!
Brett

  • 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-06-08T18:40:38+00:00Added an answer on June 8, 2026 at 6:40 pm

    The Mach kernel provides access to system clocks, out of which at least one (SYSTEM_CLOCK) is advertised by the documentation as being monotonically incrementing.

    #include <mach/clock.h>
    #include <mach/mach.h>
    
    clock_serv_t cclock;
    mach_timespec_t mts;
    
    host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock);
    clock_get_time(cclock, &mts);
    mach_port_deallocate(mach_task_self(), cclock);
    

    mach_timespec_t has nanosecond precision. I’m not sure about the accuracy, though.

    Mac OS X supports three clocks:

    • SYSTEM_CLOCK returns the time since boot time;
    • CALENDAR_CLOCK returns the UTC time since 1970-01-01;
    • REALTIME_CLOCK is deprecated and is the same as SYSTEM_CLOCK in its current implementation.

    The documentation for clock_get_time says the clocks are monotonically incrementing unless someone calls clock_set_time. Calls to clock_set_time are discouraged as it could break the monotonic property of the clocks, and in fact, the current implementation returns KERN_FAILURE without doing anything.

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

Sidebar

Related Questions

Is there a Monotonic WaitableTimer available in C#, or even in Win32 that I
If I get the time using clock_gettime(CLOCK_MONOTONIC,x), then call yield (e.g. sched_yield()), then get
If you take a look at the clock_gettime() function, which is available in all
So the clock is 18:37 right now in sweden but it prints out 16:37
Folks, in my application I'm using clock_gettime(CLOCK_MONOTONIC) in order to measure the delta time
So I know that clock() measures clock cycles, and thus isn't very good for
I started studying POSIX timers, so I started also doing some exercises, but I
I was checking out clock() on cplusplus.com . Their example involves making the process
clock http://img710.imageshack.us/img710/2623/circlock.jpg I do not know how to determine the top of the needle
In the clock app that comes with the iPhone there is a tab view

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.