diff --git a/components/buildintf/ideexterntoolintf.pas b/components/buildintf/ideexterntoolintf.pas index 842ff8defb..c43720a0f5 100644 --- a/components/buildintf/ideexterntoolintf.pas +++ b/components/buildintf/ideexterntoolintf.pas @@ -513,8 +513,9 @@ type public constructor Create(AOwner: TComponent); override; destructor Destroy; override; - procedure EnterCriticalSection; // always use before access, when using Tool and View: always lock Tool before View - procedure LeaveCriticalSection; + // always use before access, when using Tool and View: always lock Tool before View + procedure EnterCriticalSection; virtual; + procedure LeaveCriticalSection; virtual; property Thread: TThread read FThread write FThread; procedure ConsistencyCheck; virtual; procedure AutoFree; // (only main thread) free if not in use @@ -1225,14 +1226,12 @@ end; procedure TAbstractExternalTool.EnterCriticalSection; begin - Sleep(1); // Force context switch to prevent occational crash. Issue #36318, #37883 etc. FWorkerMessages.EnterCriticalSection; end; procedure TAbstractExternalTool.LeaveCriticalSection; begin Assert(Assigned(FWorkerMessages), 'TAbstractExternalTool.LeaveCriticalSection: FWorkerMessages=Nil.'); - Sleep(1); FWorkerMessages.LeaveCriticalSection; end; @@ -2355,8 +2354,8 @@ var begin if csDestroying in ComponentState then exit; Changed:=false; - EnterCriticalSection; // Beware: Tool is already in critical section - try + //EnterCriticalSection; // Beware: Tool is already in critical section !!! + //try if (FPendingLines=nil) or (FPendingProgressLine=nil) then exit; //DebugLn(['TExtToolView.ProcessNewMessages START From=',FirstMsgLine,' To=',Tool.WorkerMessages.Count-1]); NewProgressLine:=nil; @@ -2384,9 +2383,9 @@ begin PendingProgressLine.Msg:=''; end; //debugln(['TExtToolView.ProcessNewMessages END Changed=',Changed,' Progress="',ProgressLine.Msg,'"']); - finally - LeaveCriticalSection; - end; + //finally !!! + // LeaveCriticalSection; + //end; if Changed and Assigned(OnChanged) then begin // wake up main thread diff --git a/ide/exttoolsconsole.pas b/ide/exttoolsconsole.pas index fe80fac922..6638db51a7 100644 --- a/ide/exttoolsconsole.pas +++ b/ide/exttoolsconsole.pas @@ -55,6 +55,8 @@ type public constructor Create(aOwner: TComponent); override; destructor Destroy; override; + procedure EnterCriticalSection; override; + procedure LeaveCriticalSection; override; end; { TExternalToolsConsole } @@ -193,6 +195,19 @@ begin inherited Destroy; end; +procedure TExternalToolConsole.EnterCriticalSection; +begin + // A hack to prevent occational crash in LazBuild. Issue #36318, #37883 etc. + Sleep(1); // ToDo: Find the real bug and fix it. + inherited EnterCriticalSection; +end; + +procedure TExternalToolConsole.LeaveCriticalSection; +begin + Sleep(1); + inherited LeaveCriticalSection; +end; + procedure TExternalToolConsole.CreateView; // in console mode all output goes unparsed to console var