Using 33dba315366ec3002e062c3aa6dcb15b88356580 (3.3.1) My fpc.cfg looks like this / any idea?:
Threading has been used before cthreads was initialized.
Make cthreads one of the first units in your uses clause.

Mailing lists / fpc-devel / 2023-07
7 messages · 4 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Using 33dba315366ec3002e062c3aa6dcb15b88356580 (3.3.1) My fpc.cfg looks like this / any idea?:
Threading has been used before cthreads was initialized.
Make cthreads one of the first units in your uses clause.
tried 757f65d0e283c9fd33f2f99e794203590711c686
still...
19.07.2023 0:15, Martin Frb via fpc-devel пишет:
JFYI, today I have been testing a build image containing FPC 3.3.1 no older than ce37431a3f57ce11da4e8025a12a0eda3e651ff0. Just checked, config is OK there. Also compiler itself works fine.
19.07.2023 3:25, Maxim Ganetsky via fpc-devel пишет:
Hmm, I was just lucky, correct config in my case probably generated by another FPC version. ;) I see the following output of FPC 3.3.1 binary .sh installer:
Writing sample configuration file to /etc/fpc.cfg
#6 28.14 Runtime error 211 at $00000000004C0B8D
#6 28.14 $00000000004C0B8D
#6 28.14
#6 28.14 Threading has been used before cthreads was initialized. #6 28.14 Make cthreads one of the first units in your uses clause. #6 28.14 Writing sample configuration file to
/usr/lib/fpc/3.3.1/ide/text/fp.cfg
#6 28.14 Runtime error 211 at $00000000004C0B8D
#6 28.14 $00000000004C0B8D
#6 28.14
#6 28.14 Threading has been used before cthreads was initialized. #6 28.14 Make cthreads one of the first units in your uses clause. #6 28.14 Writing sample configuration file to
/usr/lib/fpc/3.3.1/ide/text/fp.ini
#6 28.14 Runtime error 211 at $00000000004C0B8D
#6 28.14 $00000000004C0B8D
#6 28.14
#6 28.14 Threading has been used before cthreads was initialized. #6 28.14 Make cthreads one of the first units in your uses clause. #6 28.15 Writing sample configuration file to /etc/fppkg.cfg #6 28.15 Runtime error 211 at $00000000004C0B8D
#6 28.15 $00000000004C0B8D
#6 28.15
#6 28.15 Threading has been used before cthreads was initialized. #6 28.15 Make cthreads one of the first units in your uses clause. #6 28.15 Writing sample configuration file to /etc/fppkg/default #6 28.15 Runtime error 211 at $00000000004C0B8D
#6 28.15 $00000000004C0B8D
#6 28.15
#6 28.15 Threading has been used before cthreads was initialized. #6 28.15 Make cthreads one of the first units in your uses clause. #6 28.15
#6 28.15 End of installation.
I am investigating the problem.
The error is logical. What is not logical is that it pops up now.
By all logic, we should have seen this error pop up as early as 2016.
Why it pops up only now is a mystery that we need to solve...
Michael.
I don't have all the details, but maybe there is something buried in the following findings.
The early call to threads happens in
#0 InitCriticalSection (cs=...) at ../inc/thread.inc:229 #1 0x000000000049ae18 in $create () at
../objpas/sysutils/sysencoding.inc:214
#2 0x00000000004a6749 in $SYSUTILS_$$_init$ () at ../unix/sysutils.pp:1903 #3 0x000000000041fc27 in $fpc_initializeunits () at ../inc/system.inc:1134 #4 0x00000000004039be in $main () at fpcmkcfg/fpcmkcfg.pp:585
sysencoding.inc:214
class constructor TEncoding.Create;
hasn't changed recently... (according to git blame)
class constructor TEncoding.Create;
var
E: TStandardEncoding;
begin
for E := Low(FStandardEncodings) to High(FStandardEncodings) do
FStandardEncodings[E] := nil;
{$ifdef FPC_HAS_FEATURE_THREADING}
InitCriticalSection(FLock);
{$endif}
end;I don't know if FPC_HAS_FEATURE_THREADING has changed?
Also
unix/sysutils.pp 1903
hasn't changed recently...
Initialization
InitExceptions; { Initialize exceptions. OS independent }
InitInternational; { Initialize internationalization settings }
SysConfigDir:='/etc'; { Initialize system config dir }
;
{$ifdef android}
InitAndroid;
{$endif android}
But the function uses a string
SysConfigDir:='/etc';Disassembly show it call "create" before InitExceptions This code must have been inserted by the compiler...
So some recent change in string handling, now inserts calls to encoding create ?
0x4a6740 <$SYSUTILS_$$_init$>: push %rbp 0x4a6741 <$SYSUTILS_$$_init$+1>: mov %rsp,%rbp 0x4a6744 <$SYSUTILS_$$_init$+4>: call 0x49ade0 <$create> 0x4a6749 <$SYSUTILS_$$_init$+9>: call 0x4a14a0 <InitExceptions> 0x4a674e <$SYSUTILS_$$_init$+14>: call 0x4a56a0 <InitInternational>
Thank you.
We already found the issue. The introduction of unit Types in unit fpmkunit (used by fpmake and fpmkcfg) caused a change in the initialization order of units.
Types depends on Math, Math depends on Sysutils -> sysutils was initialized before cthreads but uses a critical section -> cthreads detected this and raised an error.
The solution was to remove the use of cthreads in the fpmkunit unit, this is simply wrong: cthreads may only be used in the program uses clause, since otherwise there is no telling when the unit will get initialized.
We're looking at removing the dependency of Types on Sysutils: It stands to reason that defining a simple type should not introduce exception support.
We were simply lucky since around 2016 when a critical section was introduced in sysutils initialization code, necessitating the use of cthreads before sysutils.
The solution has been committed and solved the errors you were experiencing...
Michael.