Discussion:
TidSync Freezes (It never reaches DoSynchronize)
(too old to reply)
Jan Lund
2008-06-24 05:41:54 UTC
Permalink
Hello.

I'm having a problem using TidSync (D2007 Indy 10).

I use TidCmdTCPServer to receive an incoming TIdcommand (chMessageCommmad as
descibed below) from one of 8 clients.

This creates my TidSync Descendant (TSyncLogParameter) which in turn was
supposed to update a VarPanel.
TVarPanels a list of Tpanels each with a TStringgrid. Which panel to update
is being decided by TVarPanels depending of the ParamOrigin.

Now i'd expect the following sequence to happen :

TSyncLogParameter.Create
TSyncLogParameter.Synchonize
TSyncLogParameter.DoSynchronize // Update the VarPanels stringgrids
TSyncLogParameter.Free;

But what happens is that my app. freezes.

When doing a trace, i can follow it from the TSyncLogParameter.Synchronize
down to TIdNotifyThread.Run where a FEvent.WaitForEver is executed.

And i must say that this part works perfectly ;o) - it really does wait
forever....

What am i doing wrong ?
Can someone point me in the right direction ?

Best regards

Jan

procedure TJLLabPcTCP.chMessageCommand(ASender: TIdCommand);
var
x: Integer;
st : String;
VVal: String;
VName: string;
begin
if ASender.Params[3]='Param' then
Begin // This is a parameter
VName:=ASender.Params[4];
For x:=5 to ASender.Params.Count-1 Do
VVal:=VVal+' '+ASender.Params[x];
VVal:=Trim(VVal);
TSyncLogParameter.WriteParam(VarPanels,ASender.Params[2],Vname,VVal);
// Create the TidSync Descendant
End
Else
....(it is not a parameter)
end;



TSyncLogParameter = Class(TidSync)
private
FParamName : String;
FParamValue : String;
FParamOrigin : String;
FVarPanels: TVarPanels;
{ private declarations }
protected
Procedure DoSynchronize; Override;
{ protected declarations }
public
Constructor Create(VarPanels : TVarPanels;const
AParamOrigin,AparamName,AParamValue : String);
class procedure WriteParam(VarPanels : TVarPanels;const
AParamOrigin,AparamName,AParamValue : String);
{ public declarations }
end;


{ TSyncLogParameter }

constructor TSyncLogParameter.Create(VarPanels: TVarPanels; const
AParamOrigin, AparamName, AParamValue: String);
begin
FVarPanels:=VarPanels;
FParamOrigin:=AParamOrigin;
FParamName:=AparamName;
FParamValue:=AParamValue;
inherited create;
end;

procedure TSyncLogParameter.DoSynchronize;
// This is the synchronized method. You can sefely write VCL stuff here.
begin
inherited;
if Assigned(FVarPanels) then
FVarPanels.WriteParam(FParamOrigin,FParamName,FParamValue);
end;

class procedure TSyncLogParameter.WriteParam(VarPanels : TVarPanels;const
AParamOrigin, AparamName, AParamValue : String);
begin
With Create(VarPanels,AParamOrigin,AparamName,AParamValue) Do
try
Synchronize;
finally
free;
end;
end;
Remy Lebeau (TeamB)
2008-06-24 08:48:30 UTC
Permalink
Post by Jan Lund
But what happens is that my app. freezes.
The only way Synchronize() can freeze is if the main thread is not
processing queued messages, such as if the main thread has become deadlocked
elsewhere.


Gambit
Jan Lund
2008-06-24 10:44:12 UTC
Permalink
Thanks for your quick reply.

That was right on spot. I made a terrible mistake.
Outline :
I have a server and a client on both "Master" and "Slave" applications (well
actually a mulit master setup :o).
A Menu command makes the Master App TCPClient send a "Setup Message" to the
Slave Apps TCPserver.
On the slave app, the TCPServers "Setup message" handler sends a "Parameter
Message" from its TCPClient to the master apps TCPserver.
The Master App TCPserver instatiates the IDSync object, which then tries to
synchronize.

Result :
IDSync object waits for the menu command to finish.
The original Setup Message never finished (that is - the VCL menu command).

DEADLOCK!

Thanks

Jan
Post by Remy Lebeau (TeamB)
Post by Jan Lund
But what happens is that my app. freezes.
The only way Synchronize() can freeze is if the main thread is not
processing queued messages, such as if the main thread has become
deadlocked elsewhere.
Gambit
Loading...