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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:49:45+00:00 2026-06-04T03:49:45+00:00

I have a concurrent program that needs bait of clarification. The first program is

  • 0

I have a concurrent program that needs bait of clarification. The first program is considered Atomic whereas the second isn’t.

NOTE: The // don’t mean comments here – they mean that it is another process executing concurrently with the other.

Here is the first:

int x = 0, y = 0;

co
   x = y + 1;      // y = y + 1;
oc

The program above can be regarded as atomic – but I don’t understand why this is. But this next program isn’t.

int x = 0, y = 0;

co
   x = y + 1;      // y = x + 1;
oc

I know that an atomic action is a programming instruction that changes the state of a computer system indivisibly and also know that loading and storing values from/to a register is a typical atomic action. So whats going on above?

  • 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-04T03:49:47+00:00Added an answer on June 4, 2026 at 3:49 am

    In your first case you will always encounter y either before or after the increment. Since operations are async you can’t tell which, but it doesn’t make any difference — the only observable effect is that x is larger by 1 in one case rather than the other, and this could have occurred based on ordering of the two statements.

    In the second case, you can get a situation where the resulting values of x and y are not consistent with either ordering of the statements, because x and y were both fetched before either was modified.

    The first case is not really Java’s definition of “atomic” (and has nothing to do with any “atomic” directives that might be generated by the compiler), but simple programming.

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

Sidebar

Related Questions

I have created a concurrent, recursive directory traversal and file processing program, which sometimes
I have a multithreaded application that has many concurrent operations going on at once.
Under JBoss 4.0.1SP1, I have a servlet that makes multiple, concurrent calls to web
I have a program that's run in unix (that I have no control over)
I have a c# .net program where I need to first insert data into
I have a multithreaded openCV program that uses 4 threads to do the following:
On Mac OSX 5.8 I have a Java program that runs at 100% CPU
How to solve this using scala Actors: I have a program that finds out
I have a working prototype of a concurrent Scala program using Actors. I am
I am trying to have a program that uses multiple forks. I used this

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.