What is the difference between a threadvar and a local variable

后端 未结 2 1895
南笙
南笙 2021-02-06 03:35

In my threads, I always declare local variables \"normally\", thus:

procedure TMyThread.Execute ;

var
   i : integer ;

begin
i := 2 ;

etc, I

2条回答
  •  醉酒成梦
    2021-02-06 03:46

    By using ThreadVar keyword, each thread is given a separate instance of each variable, thereby avoiding data conflicts, and preserving thread independence.

    Also you do not need to protect your threadvar variables in critical sections, due to the fact that are local to the thread.

    best regards,
    Radu

提交回复
热议问题