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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:27:51+00:00 2026-06-15T22:27:51+00:00

From lot of threads, like this one, I have found that C# int/float are

  • 0

From lot of threads, like this one, I have found that C# int/float are thread safe. But I have seen lot of developers using Interlocked.Increment/CompareExchage for multi-threaded application. Any one can tell me the reason for using these constructs.
Update: I am aware about these constructs. I just wanted to ask If int is thread safe the why we need these constructs?

  • 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-15T22:27:52+00:00Added an answer on June 15, 2026 at 10:27 pm

    Any one can tell me the reason for using these constructs.

    it is not about thread safety of reading / writing. But about thread safety of the COMPLETE operation.

    Increment is read, add 1, write. With interlocked that is guaranteed to happen in one “transaction.” Same with compare/exchange.

    if you do not write it with some sort of locking, then you may get interrupted BETWEEN the operations.

    Read
    Inrecement
    Write

    Every of the 3 steps is atomic, but not the combination. Someone else may have changed the value when you write back – interlocked ensures the WHOLE operation is atomic.

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

Sidebar

Related Questions

I have a lot of pages that are setup like so from an old
We have a lot of queries select * from tbl_message that get stuck on
I have one large string which goes like this: $string = '<span id=nothread307693965>blabla here
I found a lot of threads more or less related to this topic and
I googled a lot on this but I still haven't found what I'm looking
I have a main thread that contains my WPF GUI and one or more
A lot of time I have to code from home. Normally I just remote
PrimeFaces provides a lot of icons from jQuery themeroller. They're useful but I need
Now a lot of scripts to facebook-style fetching data from url, but all of
I currently do a lot of conversions from int into a base36 string (70%~

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.