Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOmniFuture in dynamic array #131

Open
Rura1980 opened this issue Mar 15, 2019 · 4 comments
Open

IOmniFuture in dynamic array #131

Rura1980 opened this issue Mar 15, 2019 · 4 comments

Comments

@Rura1980
Copy link

I call Parallel.Future in a for loop and store IOmniFuture in a array of IOmniFuture. Later I want to iterate through this array and call future.Value for each element. Unfortunately, this code fails occasionly with TList.IndexOutOfBounds. When I wait for the future to complete before adding to dynamic array, everything works fine. What am I doing wrong?

@gabr42
Copy link
Owner

gabr42 commented Mar 15, 2019

Provide a minimal working example (http://sscce.org), please.

@Rura1980
Copy link
Author

I am using Delphi XE.
Modified code a little bit and now my program crashes (but not always) with access violation in OtlSync line 1891 FAwaitedLock.Acquire.

It seems to be something quite simple, but I cannot figure it out...
Any comments are welcomed.

program DeCalTest;

{$APPTYPE CONSOLE}

uses
FastMM4,
Windows,
SysUtils,
Classes,
SyncObjs,
Generics.Collections,
OtlParallel,
OtlCommon,
OtlCollections,
OtlTask,
OtlTaskControl;

procedure ProcessMessages;
var
Msg: TMsg;
begin
while PeekMessage( Msg, 0, 0, 0, PM_REMOVE ) do
begin
TranslateMessage( Msg );
DispatchMessage( Msg );
end;
end;

procedure TestFutures;
var
x: array of IOmniFuture;
j: integer;
begin
SetLength( x, 70 );
for j := 0 to Length( x ) - 1 do
begin
x[j] := Parallel.Future(
function: integer
begin
TThread.CurrentThread.Sleep( 100 );
Result := 0;
end
);
end;
ProcessMessages;
for j := 0 to Length(x) - 1 do
begin
Writeln( Format( 'x[%d] = %d', [j, x[j].Value] ) );
x[j] := nil;
end;
SetLength(x, 0);
x := nil;
end;

begin
ReportMemoryLeaksOnShutdown := DebugHook <> 0;
Randomize;

TestFutures;
Writeln( 'Press any key' );
ProcessMessages;
Readln;

end.

This program crashed but not always with access violation in OtlSync line 1891 FAwaitedLock.Acquire.

@gabr42
Copy link
Owner

gabr42 commented Mar 25, 2019

Sorry, but I can't repeat your problem with Delphi 10.3 Rio and latest OmniThreadLibrary source code.

@Rura1980
Copy link
Author

I cannot repeat my problem with Delphi 10.3 Rio either. Very strange.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants