title: ios/android/windows: multi read global variable but sync write access
body: <p>i have some global var (integer and single), initialised at startup and many threads access them in <strong>read only</strong>. now in very rare case (when the user change the screen orientation of the mobile) i must update all theses globales vars. </p>
  
  <p>On windows i can use a <strong>TMultiReadExclusiveWriteSynchronizer</strong>, so that thread do <em>beginread</em> before to read the variables and the main thread do <em>beginwrite</em> before to update the variables. The problem is that TMultiReadExclusiveWriteSynchronizer not work on ios/android (it's simply a  TCriticalsection on other platform)</p>
  
  <p>so is their any way to block for a moment all the thread activity that i can update peacefully all my global variable ? </p>
  
  <p>i can use AtomicCmpExchange but it's make my code much more heavy to read (i have more than 50 globals variables). </p>
  
  <p>so other option i have it's to not care about simultaneous access when updating the global var, and say later to all thread to reconstruct their internal data, <strong>BUT</strong> for exemple if i have </p>
  
  <pre><code>var w, h: single;
  w := 100.25
  h: 50;
  </code></pre>
  
  <p>and then later i do</p>
  
  <pre><code>mainThread: 
  h := 75.26
  
  Threadn:
  createbitmap(w,h);
  </code></pre>
  
  <p>then the problem is that if threadn read half written value of h, then it's could be anything like 15258425 (as i understand, i not sure) and then i will create a bitmap that will use all the memory :( </p>
  
  <p>any idea what i can do ?</p>
  
  <p><strong>EDIT / NOTE</strong></p>
  
  <p>what do you think about this implementation for my TMultiReadExclusiveWriteSynchronizer that work under android/ios/windows :</p>
  
  <pre><code>Var fLock: integer;
  
  procedure TMyMonitor.BeginWrite;
  begin
    atomicIncrement(fLock, MaxInt div 2);
    while AtomicCmpExchange(fLock{Target}, 0{NewValue}, 0{Compareand}) &lt;&gt; MaxInt div 2{OriginalOfTarget} do sleep(1);
  end;
  
  procedure TMyMonitor.EndWrite;
  begin
    atomicDecrement(fLock, MaxInt div 2);
  end;
  
  procedure TMyMonitor.BeginRead;
  begin
    while atomicIncrement(fLock{Target}) &gt;= Maxint div 2{NewValueOfTarget} do begin
      atomicDecrement(fLock);
      while AtomicCmpExchange(fLock{Target}, 0{NewValue}, 0{Compareand}) &gt;= Maxint div 2{OriginalOfTarget} do sleep(1);
    end;
  end;
  
  procedure TMyMonitor.EndRead;
  begin
    atomicdecrement(fLock);
  end;
  </code></pre>