[Lazarus] Mutlithreaded Dll Callback crashes my Application

Michael Schnell mschnell at lumino.de
Fri Aug 27 11:22:33 CEST 2010


  On 08/26/2010 08:52 PM, Alexander Grau wrote:
> To make Free Pascal's threading system to work properly, each newly 
> created FPC thread needs to be initialized (more exactly, the thread 
> local storage per thread needs to be initialized so threadvars and 
> heap are working). That is fully automatically done for you if you use 
> BeginThread (or indirectly by using the TThread class). However, if 
> you use threads that were created without BeginThread (i.e. external 
> threads),  additional work (currently) might be required. External 
> threads also include those that were created in external C libraries 
> (.DLL/.so).

FPC uses it's own way to create threadvars that is OS-specific and not 
identical with what other compilers (i.e. Microsoft C and GNU C) do.

While I do think that it would be a good idea to have the FPC RTL follow 
theses paradigms (i.e. look at the GNU docs and reverse engineer what M$ 
C does: we already investigate that; see the appropriate thread(s) in 
the FPC developers forum), I in fact don't see why this would get in the 
way with external procedures that independently use their own threadvars.

Of course when using heap managed variables (such as Pascal Strings) in 
both the main and external functions, a common heap management is 
needed, which maybe uses threadvars.

-Michael




More information about the Lazarus mailing list