* patch by Rika: fix incorrect exception handling if an exception raised in TThread decendant class's constructor, resolves #40677

This commit is contained in:
florian 2024-03-16 22:25:22 +01:00
parent c3b8b51cb5
commit 7c95ff434b
2 changed files with 3 additions and 2 deletions

View File

@ -265,6 +265,7 @@ begin
inherited Create;
{$ifdef FPC_HAS_FEATURE_THREADING}
InterlockedIncrement(ThreadQueueLockCounter);
FThreadQueueLockCounted := true; { Guard against exception in descendants Create. }
{$endif}
if FExternalThread then
{$ifdef FPC_HAS_FEATURE_THREADING}
@ -289,7 +290,7 @@ begin
RemoveQueuedEvents(Self);
DoneSynchronizeEvent;
{$ifdef FPC_HAS_FEATURE_THREADING}
if InterlockedDecrement(ThreadQueueLockCounter)=0 then
if FThreadQueueLockCounted and (InterlockedDecrement(ThreadQueueLockCounter)=0) then
DoneCriticalSection(ThreadQueueLock);
{$endif}
{ set CurrentThreadVar to Nil? }

View File

@ -2230,7 +2230,7 @@ type
FReturnValue: Integer;
FOnTerminate: TNotifyEvent;
FFatalException: TObject;
FExternalThread: Boolean;
FExternalThread, FThreadQueueLockCounted: Boolean;
FSynchronizeEntry: PThreadQueueEntry;
class function GetCurrentThread: TThread; static;
class function GetIsSingleProcessor: Boolean; static; inline;