From 1b371b15e3db1a23fb4a6100a8bac408f7ec2efe Mon Sep 17 00:00:00 2001 From: florian Date: Sun, 12 Mar 2017 09:28:41 +0000 Subject: [PATCH] * make webtbs/tw30535 also working on OSes using cthreads git-svn-id: trunk@35570 - --- rtl/unix/cthreads.pp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/rtl/unix/cthreads.pp b/rtl/unix/cthreads.pp index d87d6e3f74..491b70bc9b 100644 --- a/rtl/unix/cthreads.pp +++ b/rtl/unix/cthreads.pp @@ -306,10 +306,14 @@ Type PINTRTLEvent = ^TINTRTLEvent; pthread_exit(ThreadMain); end; - Procedure InitCThreading; + + var + TLSInitialized : longbool = FALSE; + + Procedure InitCTLS; begin - if (InterLockedExchange(longint(IsMultiThread),ord(true)) = 0) then + if (InterLockedExchange(longint(TLSInitialized),ord(true)) = 0) then begin { We're still running in single thread mode, setup the TLS } pthread_key_create(@TLSKey,nil); @@ -338,8 +342,10 @@ Type PINTRTLEvent = ^TINTRTLEvent; writeln('Creating new thread'); {$endif DEBUG_MT} { Initialize multithreading if not done } - if not IsMultiThread then - InitCThreading; + if not TLSInitialized then + InitCTLS; + IsMultiThread:=true; + { the only way to pass data to the newly created thread in a MT safe way, is to use the heap } new(ti); @@ -817,7 +823,7 @@ begin Writeln('InitThreads : ',Result); {$endif DEBUG_MT} // We assume that if you set the thread manager, the application is multithreading. - InitCThreading; + InitCTLS; end; Function CDoneThreads : Boolean;