X
X
Xvir432019-11-12 08:05:26
Delphi
Xvir43, 2019-11-12 08:05:26

How to work with tasks correctly?

Tell me how to correctly transfer parameters to the task?

Function Test(Const Xn, Wn: Array of Real): Real; 
Var
  Sum: Real; // взвешенная сумма.
  i: Integer; // счетчик.
  tasks: array of itask;
begin
  Sum := 0;
  SetLength(tasks, High(Xn));
  For i := 0 To High(Xn) Do
  begin
    tasks[i] := TTask.Create(
      procedure()
      begin
        Sum := Sum + Xn[i] * Wn[i]; // подсчет взвешенной суммы.
      end);
    for I := 0 to High(tasks) do
      tasks[i].Start;
      TTask.WaitForAll(tasks);
  end;
end;

Now it swears at Xn[i] * Wn[i], as I understand it, because you can’t access arrays from a stream, how to do it right?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question