What is the difference between passing nil in Synchronize/What is the difference between a Task/Thread?

Asked

Viewed 92 times

0

In most examples I found the structure of a basic Task is:

procedure
var
  FTask : ITask;
begin
  FTask := TTask.Run(
  procedure
  begin
    //código a ser executado dentro da Task;
    TThread.synchronize(TThread.CurrentThread,
    procedure
    begin
      //Código que executa dentro da Thread principal;
    end);
  end;
  );
end;

Where TThread.CurrentThread indicates which Thread the code will run on, but I have also seen examples of code where instead of TThread.CurrentThread is past nil, what’s the difference? How does it work? The OS will decide for itself which Thread will execute the code?

1 answer

1


This is not where the code will be executed, but what thread it will sync to. In case of passing nil will be with the Main Thread (there is only one) the Tthread.Currentthread represents the current thread, whatever it is

  • Got it, Thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.