<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Martin <<a href="mailto:fpc@mfriebe.de">fpc@mfriebe.de</a>> schrieb am Di., 1. Okt. 2019, 17:19:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I am currently looking at a strange issue in FpDebug.<br>
<br>
The main thread loads a lot of data from a file, and creates various <br>
objects.<br>
<br>
Then some code is executed in a sub-thread. The timing of that <br>
(start/stop of the 2 threads) is handled by RTLeventSetEvent / <br>
RTLeventWaitFor.<br>
This code does not seem to find (some of/ all?) the data. (for <br>
comparison, on windows the same code continues to run in the main <br>
thread, and finds the data).<br>
<br>
So the suspicion arises that maybe the thread has older data cached?<br>
<br>
Therefore my question:<br>
Does RTLeventSetEvent / RTLeventWaitFor make sure memory is synchronized <br>
between threads?<br>
<br>
//MAIN thread<br>
procedure TFpDebugDebugger.ExecuteInDebugThread(AMethod: TFpDbgAsyncMethod);<br>
begin<br>
assert(not assigned(FFpDebugThread.AsyncMethod));<br>
FFpDebugThread.AsyncMethod:=AMethod;<br>
RTLeventSetEvent(FFpDebugThread.StartDebugLoopEvent);<br>
RTLeventWaitFor(FFpDebugThread.DebugLoopStoppedEvent);<br>
RTLeventResetEvent(FFpDebugThread.DebugLoopStoppedEvent);<br>
FFpDebugThread.AsyncMethod:=nil;<br>
end;<br>
<br>
// OTHER thread<br>
procedure TFpDebugThread.Execute;<br>
begin<br>
...<br>
repeat<br>
RTLeventWaitFor(FStartDebugLoopEvent);<br>
RTLeventResetEvent(FStartDebugLoopEvent);<br>
if assigned(FAsyncMethod) then<br>
begin<br>
try<br>
FAsyncMethod();<br>
finally<br>
RTLeventSetEvent(FDebugLoopStoppedEvent);<br>
end;<br>
end;<br>
until Terminated;<br>
end;<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">The functions themselves AFAIK don't have any memory barriers, so it would depend solely on the OS primitives. </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></div>