Safe publication: does first time passing of Object reference to another thread require safe publication idioms?
<p>I have a class C with definition as given below:</p>

<pre><code>public Class C implements Runnable
{
    private B ref;
    public C(B bobj)
    {
    this.ref = bobj;                 //(0)
    }
}    

public void run()
{
    //read ‘ref’ without using synchronization.  //(4)
    //Will this read of ref see an up-to-date value or stale (may be null) value?
    //do some stuff on ‘ref’ using lock ‘ref’   
}
}
</code></pre>

<p>I have a thread T which is already running (e.g. Main thread).
Thread T creates an instance of another class B (mutable)  e.g.</p>

<pre><code>B b = new B();
</code></pre>

<p>Now it constructs an instance of class C and starts the Thread e.g.</p>

<pre><code>C runnable = new C(b);                          // (1)
new Thread(runnable).start();     //(2)
</code></pre>

<p>As per Java Language Spec 17.4.4:</p>

<blockquote>
  <p>An action that starts a thread synchronizes-with the first action in the thread it
  Starts. </p>
</blockquote>

<p>=> statement (2) above synchronizes-with statement (4).</p>

<p>Next section of same spec 17.4.5 says:</p>

<blockquote>
  <p>If an action x synchronizes-with a following action y, then we also have hb(x,
  y). </p>
</blockquote>

<p>=> here statement (2) happens-before statement (4)</p>

<p>Also, statement (1) which comes before statement (2) can not be re-ordered (otherwise a code in run() of C might detect that)by compiler as (1) comes before (2) in program order (intra-thread semantics). That means, statement (1) will come before (4) in execution order.</p>

<p>My question is whether this way of passing reference (here ‘b’) from one thread to onother is safe?</p>
