Home > Back-end >  Delphi more anonymous thread running, the thread is not running out has been hung, is operating the
Delphi more anonymous thread running, the thread is not running out has been hung, is operating the

Time:11-08

Delphi more anonymous thread running, the thread is not running have been hanging out, whether the same global variable operation problem, the thread can be early release, use fee thread execution, if it is operating the same variable how to deal with the
Test has been the Begin
Not behind the output End of the
Under D10.2 Android

CodePudding user response:

Estimation is not correct code logic leads to deadlocks

CodePudding user response:

There is no logic. Will prompt a query
Procedure TWorkPLCHandlers. UpdateMachCommSta (IsLog: Boolean);//update communication state
The begin
If IsLog then
AddMemoLog (' UpdateMachCommSta: Begin + BoolToStr (IsUptCommSta) + 'IsConn: + BoolToStr DMSYS. NTConn_SYS. IsConnected ());
If IsUptCommSta then Exit.//and server connection Or not updated (not IsLineConn) Or
IsUptCommSta:=True;
Try
TThread. CreateAnonymousThread (//to create a single thread, complete ATask
Procedure
The begin
Try
{TThread Synchronize (nil,
Procedure
The begin}
Try
With DMSYS. NTDataSet_CommSta do
The begin
The Close; SQL. The Clear;
SQL. The Add (' Update OLM_MachineLst_Sta Set CommState='+ QuotedStr (CommState) +', CommDT=GetDate () ');
SQL. The Add (' Where MachineID='+ IntToStr (MachineID));
ExecSQL;
The end;
IsUptCommSta:=False;
Except,
On e: the Exception do
The begin
IsUptCommSta:=False;
AddMemoLog (' UpdateMachCommSta: 1 error + e.M essage + 'IsUpt: + BoolToStr (IsUptCommSta));
The end;
The end;
If IsLog then
AddMemoLog (' UpdateMachCommSta: End + BoolToStr (IsUptCommSta));
//end)
Except,
On e: the Exception do
The begin
IsUptCommSta:=False;
AddMemoLog (' UpdateMachCommSta: 2 error + e.M essage + 'IsUpt: + BoolToStr (IsUptCommSta));
The end;
The end;
IsUptCommSta:=False;
The end). Start;
Except,
On e: the Exception do
The begin
IsUptCommSta:=False;
AddMemoLog (' UpdateMachCommSta: 3 error + e.M essage + 'IsUpt: + BoolToStr (IsUptCommSta));
The end;
The end;
The end;

CodePudding user response:

Your anonymous thread, the main work is done in the main thread (TThread. The Synchronize (... )), so your multithreaded has no practical significance, in addition, if multiple threads access the same components in the data module, database components, for example, can lead to abnormal
  • Related