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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:53:16+00:00 2026-05-21T16:53:16+00:00

I have found several questions about this same topic but related to general variables

  • 0

I have found several questions about this same topic but related to general variables (value and reference types)
The accepted answer from this question says:

Partition I, Section 12.6.6 of the CLI spec states: “A conforming CLI shall guarantee that read and write access to properly aligned memory locations no larger than the native word size is atomic when all the write accesses to a location are the same size.”

Reference variables (i.e. classes) are pointers, equal to the native word size, but I have a couple doubts:

Are references guaranteed to be in properly aligned memory locations?

I don’t understand the last part. What does this mean? “…when all the write accesses to a location are the same size.”

In short, is obj2 guaranteed to be valid in every iteration of the loop in the following code?

class MyClass
{
    private OtherClass m_Object;

    void Thread1()
    {
        while(true)
        {
            OtherClass obj1 = new OtherClass();
            m_Object = obj1;
        }
    }

    void Thread2()
    {
        while (true)
        {
            OtherClass obj2 = m_Object;
            // Is obj2 guaranteed to be valid?
            obj2.Check();
        }
    }
}
  • 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-21T16:53:17+00:00Added an answer on May 21, 2026 at 4:53 pm

    Yes, everything is guaranteed to be properly aligned unless you deliberately go out of your way to misalign stuff, meaning that reference assignment/reading is guaranteed to be atomic.

    Section 12.6.6 of the CLI spec goes on to say this:

    Unless explicit layout control (see
    Partition II (Controlling Instance
    Layout)) is used to alter the default
    behavior, data elements no larger than
    the natural word size (the size of a
    native int) shall be properly
    aligned. Object references shall be
    treated as though they are stored in
    the native word size.

    There are also further details about alignment etc in section 12.6.2 of the spec.

    Note that in your example code, the read in thread 2 is guaranteed to be atomic, but it’s not guaranteed to actually see any changes made by thread 1: without enforcing memory barriers or volatility each thread can use its own “view” of the m_Object field without ever seeing changes made by other threads.

    So, for example, thread 1 could be making (atomic) writes into its own view of m_Object, but the data is only ever actually held in a register or CPU cache and never comitted to main memory. Similarly, thread 2 could also be making (atomic) reads of m_Object, but actually reading from a register or CPU cache rather than main memory.

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

Sidebar

Related Questions

I have found some in the Cappuccino website (vim, textmate and SubEthaEdit), but not
I have found a few libraries to edit MP3 tags (UltraID3Lib is great) but
I have found many tutorials about using Windows Server 2003 as a development machine,
I have found ASP.Net PageMethods very handy and easy to use, but I have
I know this question has been asked several times on SO, but none of
There are several other SO questions talking about generics compiling OK w/ Eclipse's compiler
I have found that my HTML is, to be honest, very clunky. Small, simple
I have found some libraries or web services in PHP that does the job.
I have found jQuery to be a great tool to simplify my MVC Views.
I have found that there is generally a singe type or namespace that takes

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.