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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:04:46+00:00 2026-05-18T04:04:46+00:00

Say I have a bitmap, and several threads (running on several CPUs) are setting

  • 0
  1. Say I have a bitmap, and several threads (running on several CPUs) are setting bits on it. No synchronization is used, and no atomic operations. Also, no resets are done. To my understanding, when two threads are trying to set two bits on the same word, only one operation would eventually stick. The reason is that for a bit to be set, the whole word should be read and written back, and so when both reads are done at the same time, when writing back one operation would override the other. Is that correct?

  2. If the above is true, is it always so for byte operations as well? Namely, if a word is 2 bytes, and each thread tries to set a different byte to 1, will they too override each other when done concurrently, or do some systems support writing back the results to only a part of a word?

Reason for asking is trying to figure out how much space do I have to give up in order to omit synchronization in bit/byte/word-map operations.

  • 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-18T04:04:47+00:00Added an answer on May 18, 2026 at 4:04 am

    In short, it’s very CPU and compiler dependent.

    Say you have a 32-bit value containing zero, and thread A wants to set bit 0 and thread B wants to set bit 1.

    As you describe, these are read-modify-write operations, and the synchronization issue is ‘what happens if they collide’.

    The case you need to avoid is this:

    A: Reads (gets 0)
    B: Reads (also gets zero)
    A: Logical-OR bit 0, result = 1
    A: Writes 1
    B: Logical-OR bit 1, result = 2
    B: Writes 2 - oops, should have been 3
    

    … when the correct result is this…

    A: Reads (gets 0)
    A: Logical-OR bit 0, result = 1
    A: Writes 1
    B: Reads (gets 1)
    B: Logical-OR bit 1, result = 2
    B: Writes 3 - correct
    

    On some processors, the read-modify write will be three separate instructions, so you WILL need synchronization. On others, it will be a single atomic instruction. On multiple Core/CPU systems it will be a single instruction BUT other cores/CPUs may be able to access, so again you will need synchronization.

    Doing it with bytes can be the same. In some processor memory architectures, you can only write a 32-bit memory value, so byte updates require a read-modify-write as before.

    Update for X86 architecture (and windows, specifically)

    Windows provides a set of atomic "Interlocked" operations on 32-bit values, including Logical OR. These could be a big help to you in avoiding critical sections. but beware, because as Raymond Chen points out, they don’t solve everything. Keeping reading that post until you understand it!

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

Sidebar

Related Questions

Lets say I have a stack of bitmap textures char *Texture[] = { texture1.bmp,
There is something I am missing. Say I have the following code: private Bitmap
I have a large bitmap (say 3888x2592) in a file. Now, I want to
Say I have a somewhat large (i.e. not fit in most phones' memory) bitmap
Let's say I have a byte buffer and how do I get Bitmap?
I have a 2D bitmap-like array of let's say 500*500 values. I'm trying to
say I have a bitmap on my stage, and I want to load this
I have some bitmaps in a sub-folder of resource folder (say, Resource/Bitmap) and I
Let´s say I have a bitmap with 3 colors: red, green and blue (not
Let's say I have a small bitmap which contains a single digit (0..9) in

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.