Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application taking a really long time to synch threads ( or not at all )

I am using REST components in Delphi XE5 (iOS and Android). I am testing via the iOS simulator currently, and my application often hangs at the following line within my code:

R_Request.Execute;

After some debugging, I find it it specifically hangs at this line of code within the REST.Client.PAS:

HandleEvent(DoAfterExecute);

which looks like:

procedure TCustomRESTRequest.HandleEvent(AEventHandler: TMethod);
begin
  // Handle Synchronized if we are NOT already in the main thread
  // NEVER call synchronize on the MainThread - that might shift the island!
  if SynchronizedEvents and (System.MainThreadID <> TThread.CurrentThread.ThreadID) then
    TThread.Synchronize(TThread.CurrentThread, AEventHandler) // FAILS HERE
  else
    AEventHandler;
end;

It's either NOT returning the thread in the .Synchronize or taking an extremely long time ( 5 minutes or so ) ... It worked once while debugging, but has not ever since and again just now ( 30 min later, and after letting it set for 5 minutes to return a thread).

Help ? Or at least any sense of direction anyone can give me?

Again, developing for iOS and Android ( so FMX... ) and currently testing via iOS simulator. Thanks !

like image 734
ThisGuy Avatar asked Apr 14 '14 21:04

ThisGuy


1 Answers

The problem is that TThread.Synchronize() is broken in FireMonkey. See this QC report:

Report #123579: TThread.Synchronize() and TThread.Queue() do not work correctly in FireMonkey

This has only just recently been discovered, but it has been broken since FireMonkey was first introduced and nobody apparently noticed until now.

Until Embarcadero fixes it, try calling CheckSynchronize() periodically in the main thread, such as in a timer.

like image 158
Remy Lebeau Avatar answered Oct 11 '22 14:10

Remy Lebeau