Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-announce / 2018-06

Support for "class threadvar" sections inside class and record types

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Sven Barth

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

Reply by email