Discussion:
[fpc-announce] Support for "class threadvar" sections inside class and record types
Sven Barth via fpc-announce
2018-06-23 13:55:10 UTC
Permalink
Hello together!

Announcing a small feature this time, but some might appreciate it:
FPC now supports the declaration of threadvars inside class and record
types.

=== code begin ===

{$mode objfpc}
{$modeswitch advancedrecords}

type
  TTestClass = class
  public class threadvar
    Test: LongInt;
  end;

  TTestRecord = record
  public class threadvar
    Test: LongInt;
  end;

begin
  TTestClass.Test := 42;
  TTestRecord.Test := 21;
end.

=== code end ===

A threadvar section is started using "class threadvar" and the "class"
specifier is required. They are accessed like ordinary class variables
with the difference that they'll hold different values per thread - the
same as global threadvars after all.

This feature is Delphi compatible (and was added, because I noticed that
Delphi supported it and FPC did not 😅)

Regards,
Sven
_______________________________________________
fpc-announce maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/

Loading...