[Lazarus] Mutlithreaded Dll Callback crashes my Application

Sven Barth pascaldragon at googlemail.com
Fri Aug 27 11:28:40 CEST 2010


Am 27.08.2010 11:22, schrieb Michael Schnell:
> 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.

It's not about using the same threadvar system or the same heap 
management in FPC binary and non-FPC library. It's about initialising 
the FPC-internal systems PER THREAD so that you can USE theadvars, I/O, 
exceptions and such in callbacks that are coming back from the library.

Regards,
Sven




More information about the Lazarus mailing list