0

Let's say TForm1 class (default main window) contains data member int x;. If I create additional threads from TThread descendant should I use critical section object or Synchronize/Queue methods to modify value of x inside thread's Execute method?

I know that Synchronize/Queue are used when thread makes changes to VCL components. But, does that also applies here just because x is declared inside VCL's TForm1 or I can simply use critical section object instead?

Tracer
  • 2,544
  • 2
  • 23
  • 58
  • 1
    It depends. Another option are atomic increment and friends. It all depends on how the variable is used. We can't advise you what to do without that detail. – David Heffernan Apr 22 '19 at 11:20
  • Like David says, it depends on your use case. Anyway, a Critical Section is a lightweight solution comparing to using Synchronize/Queue – whosrdaddy Apr 22 '19 at 11:22

0 Answers0