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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:48:23+00:00 2026-06-06T00:48:23+00:00

I have a question regarding a race condition scenario. The question: Consider the following

  • 0

I have a question regarding a race condition scenario. The question:

Consider the following two threads, to be run concurrently in a shared
memory (all variables are shared between the two threads).

Thread A 
for i = 1 to 5 do 
  x = x + 1;

Thread B 
for j = 1 to 5 do
  x = x + 1;

Assuming a single-processor system, that load and store are atomic,
that x is initialized to 0, and that x must be loaded into a register
before being incremented (and stored back to memory afterwards), what
are all the possible values for x after both threads have completed?

Now the answer is 2:10 inclusive. I understand the results of 5:10, but how could x be 2, 3 or 4?

  • 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-06T00:48:24+00:00Added an answer on June 6, 2026 at 12:48 am

    Sequence to get x = 2:

    Thread 2 read // Reg_2 = 0
    Thread 1 read/write 4 times // x = 4
    Thread 2 write // * Reg_2 = 0 --> x = 1
    Thread 1 read // Reg_1 = 1
    Thread 2 read/write 4 times // x = 5
    Thread 1 write // Reg_1 = 1 --> x = 2
    

    Depending on how many write thread 2 does before you preempt at the step marked with *, you will get the result for 3 and 4.

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

Sidebar

Related Questions

I have question regarding shared memory segmentation in c using POSIX system calls. Is
I have a question regarding the threads that my application spawns during execution and
I have a question regarding calling methods from different threads. Well I am using
I have a question regarding inheritance, so I will describe the scenario below: I
I have a question regarding the execution of the following program. #include<stdio.h> int main(void)
I have a question regarding memory management in objective-c. I have read Apple's various
I have question regarding Java Comparator. Or maybe you all have another Idea to
I have a question regarding the two additional columns (timeCreated, timeLastUpdated) for each record
I have a question regarding the JVM memory management (at least for the SUN's
I have a question regarding GetTickCount function, I have two calls to this function

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.