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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:32:02+00:00 2026-06-10T11:32:02+00:00

I think I read that the operations on Int32 and Int64 are truly atomic

  • 0

I think I read that the operations on Int32 and Int64 are truly atomic on 64-bit systems (ie. the assembly/application is compiled as 64-bit) in .Net.

Is that true?

I can not find the MSDN citation, so I thought I’d ask you guys here.

I’m wondering if to use the Interlocked class to check and decrement the value of an Int32 from multiple threads or not, and I’m compiling it as a 64-bit application.

There’s a little help in a documentation of these methods on MSDN, but I’m not sure if I understood it correctly.

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-06-10T11:32:03+00:00Added an answer on June 10, 2026 at 11:32 am

    Re incrementing a value:

    A manual increment is never guaranteed to be atomic – not on x86, not on x64; it is four operations: load, load, add, store. The JIT might spot a load-constant-1 (ldc_i4_1 / ldc_i8) and make it a bit simpler, but fundamentally: that is not a single atomic operation. You cannot do a thread-safe increment (that does not risk lost updates) in multi-threaded code without using some kind of locking construct, or using Interlocked.

    Re assignment atomicity (aka torn values):

    Operations on int (etc) are guaranteed to be atomic by the language specification; operations on long (etc) are not guaranteed to be. Yes, it likely that they are atomic on x64, but here’s the rub: when worrying about atomicity, you must be dealing with threading. When dealing with threading, you don’t look at the implementation, i.e. what happens to be – because that is not guaranteed, and you presumably care that this code does what it intends. As such IMO you must only concern yourself with what is guaranteed, and that means: you can’t rely on long (etc) being atomic.

    Instead, use Interlocked.Increment, Interlocked.Add, etc.

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

Sidebar

Related Questions

I think I read that the delete trigger doesn't know what data was deleted
I think I read somewhere that cpu's do some floating point computations in 50
I think I read somewhere that some modules only have object oriented interfaces (
From what I've read from Herb Sutter and others you would think that volatile
We know from the C# specification that reference read/writes are atomic. In a statement
In my android application there is a number of operations that the user can
I have a map that is frequently read but rarely write to. Some operations
I can think of three operations in C++ that can be described in some
I have a wrapper class that wraps .Net's SerialPort class to perform modem operations
I think I read every single web page relating to this problem but I

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.