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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:08:59+00:00 2026-05-20T10:08:59+00:00

At memory 0x100 and 0x104 are two 32-bit counters. They represent a 64-bit timer

  • 0

At memory 0x100 and 0x104 are two 32-bit counters. They represent a 64-bit timer and are constantly incrementing.

How do I correctly read from two memory addresses and store the time as a 64-bit integer?

One incorrect solution:

x = High
y = Low
result =  x << 32 + y

(The program could be swapped out and in the meantime Low overflows…)

Additional requirements:
Use C only, no assembly
The bus is 32-bit, so no way to read them in one instruction.
Your program may get context switched at any time.
No mutex or locks available.

Some high-level explanation is okay. Code not necessary. Thanks!

  • 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-20T10:08:59+00:00Added an answer on May 20, 2026 at 10:08 am

    I learned this from David L. Mills, who attributes it to Leslie Lamport:

    1. Read the upper half of the timer into H.
    2. Read the lower half of the timer into L.
    3. Read the upper half of the timer again into H’.
    4. If H == H’ then return {H, L}, otherwise go back to 1.

    Assuming that the timer itself updates atomically then this is guaranteed to work — if L overflowed somewhere between steps 1 and 2, then H will have incremented between steps 1 and 3, and the test in step 4 will fail.

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

Sidebar

Related Questions

A bit of background information: Inorder to read/write to SLE4442 memory cards, my app
Let's say I have allocated several pages of continuous memory using VirtualAlloc() from 0x06000000
Memory leak problem - NSConcreteData // to set tip - photo in photo frame
Memory management is a very important issue in iPhone. So I am asking a
What memory leak detectors have people had a good experience with? Here is a
What memory leak detection tools are available for use with open source C/C++ on
How memory is allocated in case of spawning a new thread, i.e how memory
I have a .z80 memory dump. How do I reverse engineer it? What do
I'm writing the memory manager for an application, as part of a team of
I have a memory buffer corresponding to my screen resolution (1280x800 at 24-bits-per-pixel) that

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.