[Lazarus] Mutlithreaded Dll Callback crashes my Application
Alexander Grau
alex at grauonline.de
Wed Aug 25 20:24:38 CEST 2010
José Mejuto schrieb:
> Hello Lazarus-List,
>
> Wednesday, August 25, 2010, 8:44:53 AM, you wrote:
>
> MW> I've packed the runtime env dlls and put them on my ftp server.
> MW> They are too big to attach to the mail on the list.
>
> Do you have compiled the "vcmtdll.dll" with Multithread runtime
> library (/MT) ?
>
> To avoid crashes just simply:
>
> // start threads
> for index := 0 to FThreads.Count-1 do
> begin
> TVCMTThread(FThreads.Items[index]).Start(10);
> Sleep(50);
> end;
>
> Adding the Sleep(50) avoids any crash, and the AsyncWrite works as
> expected. You should also add a Sleep(50) after each FThreads[n].free
>
> If a multithread problem is solved with sleeps usually it is a race
> condition in the RTL, in this case you create a new thread while the
> provious one is being created (or destroyed), so to me looks like a
> VC++ non multithread RTL problem.
>
> It is also desirable to add the line "IsMultithread:=true" in the
> first line of .lpr (after the begin) to activate the Multithread RTL
> in the FPC, otherwise it could not be active.
>
> I had tested it with 200 threads and using the sleeps no problem at
> all.
>
Hello José,
I have tried to reduce the DLL problem into a test that doesn't need any
external DLL. It crashes too.
Here's the test program:
http://grauonline.de/alexwww/tmp/extthread.zip
Can you see any analogy to the problem? I have tried to add your
suggested "IsMultithread:=true" and it doesn't make any difference. I
think there's something wrong in the FPC runtime.
Regards,
Alexander
More information about the Lazarus
mailing list