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

  • Home
  • SEARCH
  • 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 7688983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:03:29+00:00 2026-05-31T20:03:29+00:00

I was wondering if there’s a windows API to set a 16-byte array atomically?

  • 0

I was wondering if there’s a windows API to set a 16-byte array atomically?

I would really hate to introduce critical sections or mutexes into this just to implement this operations, so I’m trying to find an easier solution.

PS. I need this because this 16-byte array can be written into from a worker thread, and mostly read from a main thread.

  • 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-31T20:03:30+00:00Added an answer on May 31, 2026 at 8:03 pm

    All of the following assumes a 64-bit x86_64 architecture. I believe that in general what you asked for is not possible on 32-bit x86.

    There are really two options. The first one is _InterlockedCompareExchange128, which translates to LOCK CMPXCHG16B. To duplicate the functionality of a 16-byte store with it, you’d need to do something like this:

    __int64* dest = ...;
    __int64* orig = ...;
    unsigned char ok;
    do
    {
        __int64 high = dest[0];
        __int64 low  = dest[1];
        ok = _InterlockedCompareExchange128(dest, high, low, orig);
    }
    while (!ok);
    

    Note that because this is an interlocked operation, it implies the equivalent of a _ReadWriteBarrier. This is normally what is meant by an “atomic” operation.

    If you want a pure store, not a compare-exchange, then you can use anything that translates to an aligned 16-byte store on the hardware. For example, the MOVDQA instruction would qualify. In C++, that’d look something like this:

    __m128i* dest = ...;
    _mm_mfence();
    _mm_store_si128(dest, _mm_loadu_si128((__m128i*)&orig));
    _mm_mfence();
    

    Unless you have a reason to avoid SSE instructions, I think the second version might perform better. You also may want to decide if you want to relax the two memory barriers depending on your actual needs.

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

Sidebar

Related Questions

Wondering if there is some preference I can set in excel so that when
Hi there I am wondering if there an inbuilt or available api to gather
Wondering if there is a way upon clicking on a hyper link to set
I was wondering there type of API like onStart and onComplete from Mootools, it
I know mutex can be an implementation, however I'm wondering there would be a
Wondering if there is any Text to Speech software available as a plug in
Wondering if there's any not-too-hard way to edit non-form text in html 4. I
Wondering if there is any way to get the lambda expressions that result from
Wondering if there is a good way to generate temporary URLs that expire in
Just wondering if there is an easy way to add the functionality to duplicate

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.