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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:54:07+00:00 2026-06-11T04:54:07+00:00

Consider a simple, single-threaded Java program execution involving no synchronization actions, just plain reads

  • 0

Consider a simple, single-threaded Java program execution involving no synchronization actions, just plain reads and writes of instance variables. An implementation that simply ignores all writes seems to comply with the Java Memory Specification. First, the applicable general statement from §17.4:

The memory model determines what values can be read at every point in the program. The actions of each thread in isolation must behave as governed by the semantics of that thread, with the exception that the values seen by each read are determined by the memory model.

The relevant constraints would be the following (§17.4.5):

1. happens-before ordering induced by program order:

If x and y are actions of the same thread and x comes before y in program order, then hb(x, y).

2. happens-before consistency:

A set of actions A is happens-before consistent if for all reads r in A, where W(r) is the write action seen by r, it is not the case that either hb(r, W(r)) or that there exists a write w in A such that w.v = r.v and hb(W(r), w) and hb(w, r).

This basically precludes a read happening-before the write it observes. The other provision is just a sanity clause that prevents a read of some v seeing an earlier write of that v that was in the meantime followed by another write of the same v.

I cannot find any guarantee whatsoever that a write will positively be observed, only restrictions on what writes may not be observed.

What am I missing here? Is it really possible that the JVM leaves out such a trivial guarantee?

  • 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-11T04:54:08+00:00Added an answer on June 11, 2026 at 4:54 am

    Let’s use:

    class MyClass {
        private static int i = 0;
    
        public static void main(String[] args) {
            i = 3; //w
            System.out.println(i); //r
        }
    }
    
    • A program is correctly synchronized if and only if all sequentially consistent executions are free of data races.
    • If a program is correctly synchronized, then all executions of the program will appear to be sequentially consistent (§17.4.3).
    • When a program contains two conflicting accesses (§17.4.1) that are not ordered by a happens-before relationship, it is said to contain a data race.

      Your program is single threaded
      => we have hb(w,r) from the program order constraint
      => it is correctly synchronized
      => all executions of the program will appear to be sequentially consistent.
      => it will print 3

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

Sidebar

Related Questions

I have a single AMQ queue that receives simple messages with string body. Consider
I've got, what I would consider, a simple test web site. A single page
Consider the requirements for embedding help in a Java desktop application (or applet): Single
Consider simple Java application which should traverse files tree in a disc to find
Consider the following example (a simple 2d vector lib). Here there is a single
Consider simple multiple select box <select name=waste id=waste multiple> <option value=5>garbage</option> <option value=6>food</option> <option
Consider a simple JS event of document.getElementsByClassName('test')[0].onclick=function(){ document.getElementsByClassName('test')[0].innerHTML = 'New Text'; } How can
Consider this simple model: A base Location table: +-------------------------------+ | Locations | +-------------------------------+ |(PK)
Consider a simple JS function as function test(property, color) { var element = document.getElementById(test);
consider this simple function def foo(l=[]): if not l: print List is empty else

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.