This question already has an answer here:
Unexpected Thread behaviour calling Delphi DLL
DLL and class in multithreaded application
I have faced following issue:
When calling the DLL function in parallel from multiple threads I get the "EAggregateException: One or more errors occurred".
The minimal DLL example is:
procedure MyUpper(const ASource: WideString; out AResult: WideString); stdcall;
AResult := String(ASource).ToUpper;
The application which uses it:
procedure MyUpper(const AText: WideString; out AResult: WideString); stdcall; external 'MyDLL.dll';
LSync := TSimpleRWSync.Create;
LLoop := TParallel.&For(1, 100000,
procedure (AIndex: Integer)
Writeln('Completed: ', LLoop.Completed);
on E: Exception do
Writeln(E.ClassName + ': ' + E.Message);
If in EXE I write following:
AResult := ASource;
Then the execution succeeds. But once I use any implicit/explicit string conversion it fails. How that could be? Each thread calls this method as an usual method with it's local stack and there is no shared variables (at least visible).
I don't use any shared memory manager as I am going to use the DLL from different programming languages.
What I am doing wrong?
Thank you in advance.