4
I have a situation where in Delphi I have two threads that perform a function that ping in a Firebird database.
I use this to sync data from my PDV (sending and receiving).
But as they run at the same time sometimes occurs a lock Dead in BD.
--
My job:
function TTPingRede(const IP: AnsiString; TimeOut: Integer = 250) : Boolean;
var
DW: DWORD;
Handle: THandle;
InAddr: IPAddr;
Arq: TextFile;
Rep: array[1..128] of byte;`
begin
try
DW := 99;
Result := False;
Handle := IcmpCreateFile;
if (Handle <> INVALID_HANDLE_VALUE) then
begin
try
TranslateStringToTInAddr(PansiChar(IP), InAddr);
DW := IcmpSendEcho(Handle, InAddr, nil, 0, nil, @rep, 128, TimeOut);
Result := (DW <> 0);
vStatusREDE_ATIVA := Result;
except
DW := 0;
Result := False;
end;
try
Dm.qStatusRede.Close;
Dm.qStatusRede.SQL.Clear;
Dm.qStatusRede.SQL.Add('UPDATE TBSINCRO001');
Dm.qStatusRede.SQL.Add('SET');
Dm.qStatusRede.SQL.Add(' STATUS_REDE_SERVIDOR = :P0');
Dm.qStatusRede.Params[0].AsInteger := DW;
Dm.qStatusRede.Prepare;
Dm.qStatusRede.ExecSQL;
if Dm.Tr_StatusRede.InTransaction then Dm.Tr_StatusRede.Commit;
except
on E: Exception do
begin
Dm.Tr_StatusRede.Rollback;
GerarLogErroSincronizar('1:FUNC ENV|'+E.Message);
end;
end;
end;
finally
IcmpCloseHandle(Handle);
end;
end;
I would like to know an implementation that I can drip into the bank without the Dead lock.
Here is the Portuguese version, you need to translate the question.
– rray
I don’t know why I’m using two threads for the same goal, but the simplest (and obvious) way to solve it would be to just leave one thread... Another way would be using "Critical sections"... Search Google about this and see also this video https://www.youtube.com/watch?vJiX5ra36Las
– Guybrush