revalNG / omnithreadlibrary

Automatically exported from code.google.com/p/omnithreadlibrary
0 stars 0 forks source link

TOmniParallelJoin.Execute #26

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Get OmniThreadLibrary-3.01.zip
2. Open tests\37_ParallelJoin\app_37_ParallelJoin.XE2.dproj
3. I changed the method for following code btnJoinAllClick

procedure TfrmTestParallelJoin.btnJoinAllClick(Sender: TObject);
var
  expectedTime: integer;
  Join: IOmniParallelJoin;
  startTime: int64;
begin
  if Sender = btnJoinOne then
    expectedTime := 5
  else
    expectedTime := 3;
  Log(Format('Starting two tasks, expected execution time is %d seconds',
    [expectedTime]));
  startTime := DSiTimeGetTime64;
  Join := Parallel.Join(
    procedure(const joinState: IOmniJoinState)
    begin
      Sleep(3000);
    end,
    procedure(const joinState: IOmniJoinState)
    begin
      Sleep(2000);
    end);

  {My Code}
  Join.Task(procedure(const joinState: IOmniJoinState)
    begin
      Sleep(10000);
    end);

  if Sender = btnJoinOne then
    Join.NumTasks(1);

  Join.Execute;
  Log(Format('Tasks stopped, execution time was %s seconds',
    [FormatDateTime('s.zzz', DSiElapsedTime64(startTime) / MSecsPerDay)]));
end;

What is the expected output? What do you see instead?
the software would have to wait 10,000 milliseconds, but an exception occurs.

What version of the product are you using? On what operating system?
OmniThreadLibrary-3.01

Please provide any additional information below.

I fixed this bug by changing the unit OtlParallel.pas
changed the following method
function TOmniParallelJoin.Execute: IOmniParallelJoin;

Original:

function TOmniParallelJoin.Execute: IOmniParallelJoin;
var
  iProc      : integer;
  numTasks   : integer;
  taskControl: IOmniTaskControl;
begin
  numTasks := opjNumTasks;
  if numTasks > opjTasks.Count then
    numTasks := opjTasks.Count;

Mine:

function TOmniParallelJoin.Execute: IOmniParallelJoin;
var
  iProc      : integer;
  numTasks   : integer;
  taskControl: IOmniTaskControl;
begin
  numTasks := opjNumTasks;
  if numTasks < opjTasks.Count then
    numTasks := opjTasks.Count;

Original issue reported on code.google.com by Passe...@gmail.com on 24 May 2012 at 4:41

Attachments:

GoogleCodeExporter commented 8 years ago
This code segment seems fine to me - if user set NumTasks to a number, larger 
than total count of Join tasks, this number is reduced to total number of Join 
tasks.

However, the code crashes when run on a single CPU. I'll check what's going on.

Original comment by gabr42 on 25 May 2012 at 10:00

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
This is now fixed in the SVN. Thanks for reporting the problem!

Original comment by gabr42 on 3 Jun 2012 at 4:11