AThreads: ThreadInfo for the main thread move to a global var to prevent problems with heap manager

This commit is contained in:
Marcus Sackrow 2023-02-19 14:09:29 +01:00 committed by Karoly Balogh
parent ac93ad48e3
commit 0c5256300a

View File

@ -83,6 +83,7 @@ type
var
AThreadManager: TThreadManager;
AThreadMainThreadInfo: TThreadInfo;
AThreadList: PThreadInfo;
AThreadListLen: LongInt;
AThreadNum: LongInt;
@ -394,7 +395,10 @@ begin
SysDebugLn('FPC AThreads: Entering multithreaded mode...');
{$endif}
p:=PProcess(FindTask(nil));
new(threadInfo);
{ the main thread info is allocated as a global var, it is the cleanest solution,
as it can never really be freed after threading was initialized, due to clashes
with threadvar handling in heap managers, etc. }
threadInfo:=@AThreadMainThreadInfo;
FillChar(threadInfo^,sizeof(TThreadInfo),0);
p^.pr_Task.tc_UserData:=threadInfo;
threadInfo^.mainThread:=true;