title: @volatile usage unclear - sending an object with a `var` to another thread
body: <p>I am not sure I use <code>@volatile</code> correctly here. I have a buffer, like this:</p>
  
  <pre><code>final class BufD(val buf: Array[Double], @volatile var size: Int)
  </code></pre>
  
  <p>Which is sent between processes, whereby it might cross thread boundaries. The sender may update the <code>size</code> field just before sending it out. Therefore I want to make sure that the receiver under no circumstances can see a stale <code>size</code> value here. <strong>First question:</strong> Does <code>@volatile</code> ensure this or is it redundant?</p>
  
  <p>Now I am introducing a trait:</p>
  
  <pre><code>trait BufLike {
    @volatile var size: Int
  }
  
  final class BufD(val buf: Array[Double], @volatile var size: Int) extends BufLike
  </code></pre>
  
  <p>This gives me a compiler warning:</p>
  
  <blockquote>
    <p>Warning:(6, 4) no valid targets for annotation on method size - it is discarded unused. You may specify targets with meta-annotations, e.g. @(volatile @getter)</p>
  
  <pre><code> @volatile var size: Int
    ^
  </code></pre>
  </blockquote>
  
  <p><strong>Second question:</strong> Should I remove the <code>@volatile</code> here or change it in a different way?</p>