[fpc-devel] TThread.Terminate;
Jonas Maebe
jonas at freepascal.org
Sat Aug 22 18:45:26 CEST 2020
On 22/08/2020 17:39, Martin Frb via fpc-devel wrote:
> I guess the "Terminate" field is actually about cache coherency.
Yes, but as mentioned earlier it's in general completely useless to
force the overhead of cache coherency for it. By design it's not
something that will be checked immediately after it gets set, so who
cares if the target thread doesn't see its new value immediately?
If you do care, then you need some other way to signal the target thread
to immediately drop what it's doing, but then there is no point in
checking the Terminated property anymore since that signal will already
have performed the same function.
> I would assume that InterLocked will make sure (maybe as side effect)
> that there is cache coherency ?
> I.e. it makes sure (on all platforms) that the particular value that it
> did set, will be immediately visible to all other threads (if they use
> interlocked.... to read it)?
Yes.
> At least that is what I always thought. If that is not the case, I have
> a lot of code to fix...
> I acknowledge that
> - a value set with InterlockedExchange by one thread
> - may not be visible in other threads, if the access it *without*
> InterlockedExchange
> - does not affect the visibility of any other memory between threads.
>
> How far off am I ?
It's correct.
Jonas
More information about the fpc-devel
mailing list