diff --git a/.gitattributes b/.gitattributes index 8b79287a21..b9d223f5fd 100644 --- a/.gitattributes +++ b/.gitattributes @@ -15341,6 +15341,7 @@ tests/webtbs/tw30524a.pp svneol=native#text/pascal tests/webtbs/tw30524b.pp svneol=native#text/pascal tests/webtbs/tw30530.pp svneol=native#text/pascal tests/webtbs/tw30534.pp svneol=native#text/pascal +tests/webtbs/tw30535.pp svneol=native#text/pascal tests/webtbs/tw30537.pp svneol=native#text/pascal tests/webtbs/tw30552.pp svneol=native#text/pascal tests/webtbs/tw30570.pp svneol=native#text/plain diff --git a/rtl/inc/heaptrc.pp b/rtl/inc/heaptrc.pp index c029eb253d..29e403fc91 100644 --- a/rtl/inc/heaptrc.pp +++ b/rtl/inc/heaptrc.pp @@ -1446,9 +1446,14 @@ begin {$endif EXTRA} { if multithreading was initialized before heaptrc gets initialized (this is currently the case for windows dlls), then RelocateHeap gets never called and the lock - must be initialized already here + must be initialized already here, + + however, IsMultithread is not set in this case on windows, + it is set only if a new thread is started } +{$IfNDef WINDOWS} if IsMultithread then +{$EndIf WINDOWS} TraceRelocateHeap; end; diff --git a/rtl/win/systhrd.inc b/rtl/win/systhrd.inc index 809c73ed72..80e85a3f63 100644 --- a/rtl/win/systhrd.inc +++ b/rtl/win/systhrd.inc @@ -141,7 +141,7 @@ var function SysRelocateThreadvar(offset : dword) : pointer; forward; - procedure SysInitMultithreading; + procedure SysInitTLS; begin { do not check IsMultiThread, as program could have altered it, out of Delphi habit } @@ -151,8 +151,6 @@ var { We're still running in single thread mode, setup the TLS } TLSKey^:=TlsAlloc; InitThreadVars(@SysRelocateThreadvar); - - IsMultiThread:=true; end; end; @@ -250,7 +248,8 @@ var writeln('Creating new thread'); {$endif DEBUG_MT} { Initialize multithreading if not done } - SysInitMultithreading; + SysInitTLS; + IsMultiThread:=true; { the only way to pass data to the newly created thread in a MT safe way, is to use the heap } @@ -544,7 +543,7 @@ begin {$ifndef FPC_USE_TLS_DIRECTORY} if IsLibrary then {$endif} - SysInitMultithreading; + SysInitTLS; {$IFDEF SUPPORT_WIN95} { Try to find TryEnterCriticalSection function } KernelHandle:=GetModuleHandle(KernelDLL); diff --git a/tests/webtbs/tw30535.pp b/tests/webtbs/tw30535.pp new file mode 100644 index 0000000000..462f6f908f --- /dev/null +++ b/tests/webtbs/tw30535.pp @@ -0,0 +1,10 @@ +{$ifdef unix} +uses + cthreads; +{$endif} + +begin + if IsMultiThread then + halt(1); + Writeln('ok'); +end.