<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p>Really, insofar as x86 is concerned, the only ones that are
      guaranteed to be atomic are, I think, the ordinal types, but that
      still leaves problems of code such as the following:</p>
    <p>if GlobalCounter = 10 then<br>
      begin<br>
        DoSomething;<br>
        Break;<br>
      end else<br>
        Inc(GlobalCounter);</p>
    <p>If two threads are running a loop with the following code at the
      end, it could be that GlobalCounter is 9, the condition is
      checked, but before Inc(GlobalCounter) is called, the scheduler
      switches to the other thread, where GlobalCounter is checked and
      is still 9, and is then incremented, and only then does it switch
      back to the other thread, where Inc(GlobalCounter) is finally
      called, thereby setting GlobalCounter to 11 and breaking the
      program.</p>
    <p>In this instance, a critical section or some other mutex is
      required, or the interlocked instructions, all of which incur a
      performance penalty.</p>
    <p>Definitely something for a lot of discussion!<br>
    </p>
    <p>Gareth aka. Kit</p>
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 02/07/2019 08:13, Benito van der
      Zander wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:cbee0e5f-e9e5-cea2-dced-d9722c779db0@benibela.de">
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <div id="smartTemplate4-template">Hi,<br>
        <br>
        <div class="moz-cite-prefix">Am 28.06.19 um 11:24 schrieb George
          Bakhtadze:<br>
        </div>
        <blockquote type="cite"
          cite="mid:1455841561713884@iva8-bad53723c646.qloud-c.yandex.net">
          <div>If FPC somehow guarantees that a global field (even only
            of simple types) can be atomically read and written from any
            thread for ANY platform that is a very strong guarantee and
            worth mention in documentation.</div>
        </blockquote>
        <p> btw, how would you do that if it is in not guaranteed?
          especially on arm<br>
        </p>
        Are there functions to do only an atomic reads and writes?
        (besides functions like interlockedincrement that do both, a
        read and write, together)<br>
        <br>
        Best,<br>
        Benito <br>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
fpc-devel maillist  -  <a class="moz-txt-link-abbreviated" href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a>
<a class="moz-txt-link-freetext" href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</a>
</pre>
    </blockquote>
  <div id="DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2"><br />
<table style="border-top: 1px solid #D3D4DE;">
        <tr>
        <td style="width: 55px; padding-top: 13px;"><a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient" target="_blank"><img src="https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif" alt="" width="46" height="29" style="width: 46px; height: 29px;" /></a></td>
                <td style="width: 470px; padding-top: 12px; color: #41424e; font-size: 13px; font-family: Arial, Helvetica, sans-serif; line-height: 18px;">Virus-free. <a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient" target="_blank" style="color: #4453ea;">www.avast.com</a>
                </td>
        </tr>
</table><a href="#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2" width="1" height="1"> </a></div></body>
</html>