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