Recent

Author Topic: ThreadVar variables.  (Read 2954 times)

taazz

  • Hero Member
  • *****
  • Posts: 5368
ThreadVar variables.
« on: October 31, 2015, 04:36:28 pm »
I think I finally found a valid use of a ThreadVar variable but since this is going to be my first attempt to use them I have 2 basic questions.
1) How is a ThreadVar initialized? I plan to use a numeric variable either cardinal or QWord, I need it to be initialized to 0 on all threads accessing it.
2) Can I have threadVar object fields? something along the line of
Code: [Select]
type
  TMyAwesomelyDumClass
  Private
    ThreadVar
      FMyPerThreadVariable:DWord;
  .
  .
  .
  .
    function MyPerThreadVar : DWord Read FMyPerThreadVariable write FMyPerThreadVariable; // this can be anything really its here to show some kind of access.
  end;
Keep in mind, I know not what I'm talking about.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: ThreadVar variables.
« Reply #1 on: October 31, 2015, 09:05:24 pm »
You can't define a threadvar inside a class. You need to place it outside of the class.

See this for more info : http://www.freepascal.org/docs-html/ref/refse24.html
« Last Edit: October 31, 2015, 09:07:11 pm by Cyrax »

 

TinyPortal © 2005-2018