title: String array - needless synchronization?
body: <p>I'm studying ChronicleHFT libraries. I found a class <code>StringInterner</code> posted below</p>
  <pre><code>public class StringInterner {
      @NotNull
      protected final String[] interner;
      protected final int mask;
      protected final int shift;
      protected boolean toggle = false;
  
      public StringInterner(int capacity) throws IllegalArgumentException {
          int n = Maths.nextPower2(capacity, 128);
          this.shift = Maths.intLog2((long)n);
          this.interner = new String[n];
          this.mask = n - 1;
      }
  
      @Nullable
      public String intern(@Nullable CharSequence cs) {
          if (cs == null) {
              return null;
          } else if (cs.length() &gt; this.interner.length) {
              return cs.toString();
          } else {
              int hash = Maths.hash32(cs);
              int h = hash &amp; this.mask;
              String s = this.interner[h];
              if (StringUtils.isEqual(cs, s)) {
                  return s;
              } else {
                  int h2 = hash &gt;&gt; this.shift &amp; this.mask;
                  String s2 = this.interner[h2];
                  if (StringUtils.isEqual(cs, s2)) {
                      return s2;
                  } else {
                      String s3 = cs.toString();
                      this.interner[s != null &amp;&amp; (s2 == null || !this.toggle()) ? h2 : h] = s3;
                      return s3;
                  }
              }
     
  </code></pre>
  <p>I found yt video from Peter Lawrey on which he explains (or to be more precise - he just says) that this class is thread safe and doesn't need any additional synchronization to work in multithreaded environment. Video yt link: <a href="https://www.youtube.com/watch?v=sNSD6AUG5a0&amp;t=1200" rel="nofollow noreferrer">https://www.youtube.com/watch?v=sNSD6AUG5a0&amp;t=1200</a></p>
  <p>My question is why this class doesn't need any sync?</p>
  <ol>
  <li>How about visibility - if one thread put something into interner[n], does another threads are guaranteed to see it?</li>
  <li>What happens in case, when scheduler yields a thread in the middle of method? Does it lead to put same value in same index twice?</li>
  </ol>