Am 08.10.2010 13:33, schrieb Graeme Geldenhuys:
Hi,

Is it the line with InterlockedExchange() call?  The reason I ask, I'm
using FPC 2.4.3 under 64-bit linux and using fpGUI. All other
platforms has a clear 'IsMultiThreaded := True' in the RTL code, but
not for Unix. It seems CheckSynchronized() is never called in
fpGUI/X11 because IsMultiThread is never True, even though I have
'cthreads' unit defined as the first unit in my fpGUI program.


-------------[ rtl/unix/cthreads.pp]------------------
....
       { Initialize multithreading if not done }
       if not IsMultiThread then
         begin
           if (InterLockedExchange(longint(IsMultiThread),ord(true)) = 0) then
             begin
               { We're still running in single thread mode, setup the TLS }
               pthread_key_create(@TLSKey,nil);
               InitThreadVars(@CRelocateThreadvar);
             end
         end;
....
-------------------------------


In fpGUI, CheckSynchronized is executed as follows in the main event loop.


....
   if IsMultiThreaded then
     CheckSynchronized();
...



InterlockExchange does exactly that. It writes "ord(true)" to "longint(IsMultiThread)" and returns its old value (0 = ord(false)).

Note: You must start at least one thread (besides the main thread) to turn "IsMultiThread" to true.

Btw: the check for IsMultiThread inside of RTL code is a bit dangerous as ported Delphi applications might set it manually to true out of old habit (which is bad if the multithreading initialization checks that var).

Regards,
Sven
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to