<div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml">14.12.2018, 13:17, "Martin Frb" <lazarus@mfriebe.de>:</div><blockquote xmlns="http://www.w3.org/1999/xhtml" type="cite"><div bgcolor="#FFFFFF"><div> </div>Could "Thread.FFinished := True;"  be moved to the top? (potentially together with   "Result := Thread.FReturnValue;" so the order of those 2 remains).<br /><br />The reason is, that then (on a suspended thread) it would be save to change "FreeOnTerminate" if "Finished = False".<br /><br />This should be ok, the doc <a rel="noopener noreferrer" href="https://www.freepascal.org/docs-html/rtl/classes/tthread.finished.html">https://www.freepascal.org/docs-html/rtl/classes/tthread.finished.html</a> explicitly states that when it is true "the thread is still cleaning up (calling OnTerminate, etc)."</div></blockquote><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml">It still will not be safe as the value of Finished property may not immediately become visible to other threads.</div><div xmlns="http://www.w3.org/1999/xhtml">There is no guarrantee of ordering all operations in a thread from other threads point of view.</div><div xmlns="http://www.w3.org/1999/xhtml">Operations may be reordered, the result may be cached and so on.</div><div xmlns="http://www.w3.org/1999/xhtml">The order is guaranteed only for so called synchronization points. For example, entering or leaving a critical section.</div>