[fpc-pascal] Call function in shared library from multiple threads

Michael Van Canneyt michael at freepascal.org
Fri Mar 31 17:56:42 CEST 2017



On Fri, 31 Mar 2017, fredvs wrote:

> Hello.
>
>
> Michael Van Canneyt wrote
>> To fix that, you can do the following. 
>> In the library startup code, create a dummy thread. 
>> This will initialize the threads mechanism:
>>
>>    with TThread.Create(False) do
>> 
>> end.
>
> I use this for initialize my libraries:


Best is probably:

Type
   TDummyThread = Class(TThread)
   public
     procedure execute; override;
   end;

procedure TDummyThread.Execute;

begin
   FreeOnTerminate:=True;
   Terminate;
end;


begin
   TDummyThread.Create(True)
end.


Michael.



More information about the fpc-pascal mailing list