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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:39:46+00:00 2026-05-22T22:39:46+00:00

When are writes that are performed by one thread visible to a different thread

  • 0

When are writes that are performed by one thread visible to a different thread when there are no synchronized blocks and no volatile variables? Here is a simplified quicksort example:

int middle = partitionForTheFirstTime(array);

Thread t = new Thread(new Quicksorter(array, 0, middle - 1));
Thread u = new Thread(new Quicksorter(array, middle + 1, array.size - 1));

t.start()
u.start();

t.join();
u.join();

(For the sake of simplicity, assume that the two “worker threads” do not spawn any additional threads.)

Does joining with the two threads guarantee that the current thread sees all their side effects?


On a related note, what would happen if I created the threads before the initial partitioning?

Quicksorter a = new Quicksorter();
Quicksorter b = new Quicksorter();

Thread t = new Thread(a);
Thread u = new Thread(b);

int middle = partitionForTheFirstTime(array);

a.setParameters(array, 0, middle - 1);
b.setParameters(array, middle + 1, array.size - 1);

t.start()
u.start();

t.join();
u.join();

Will the two threads be able to see the side effects caused by partitionForTheFirstTime()? In other words, does creating a Thread incur a happens-before relationship, or does starting a Thread?

  • 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-22T22:39:47+00:00Added an answer on May 22, 2026 at 10:39 pm

    From section 17.4.5 of the JLS:

    It follows from the above definitions that:

    • An unlock on a monitor happens-before every subsequent lock on that monitor.
    • A write to a volatile field (§8.3.1.4) happens-before every subsequent read of that field.
    • A call to start() on a thread happens-before any actions in the started thread.
    • All actions in a thread happen-before any other thread successfully returns from a join() on that thread.
    • The default initialization of any object happens-before any other actions (other than default-writes) of a program.

    The bits about start() and join() are the relevant ones for you – in other words, when you’ve join()-ed a thread successfully, you see all actions in that thread. If you start() a thread, that new thread will see all the actions which have already occurred in the thread which calls start().

    EDIT: Also see "memory consistency errors".

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

Sidebar

Related Questions

I have one thread that writes results into a Queue. In another thread (GUI),
Over in this question, Scott writes that it is possible to get the current
I got a program that writes some data to a file using a method
I have an application that writes to another application and needs to provide the
I'm developing software that writes to a tiny LCD screen (less than 1 x
I have an application that writes information to file. This information is used post-execution
We have a custom service that writes to a DB (SQL 2005). This is
I have created an application that writes some data to the root folder of
Quick question here: is there any obvious benefit to use asynchronous communication with the
After some serious googleing I found out that the RandomAccessFile-class is not thread-safe. Now

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.