[fpc-devel] OO rewrite - technical questions

Michael Schnell mschnell at lumino.de
Mon Jul 19 14:44:50 CEST 2010


  On 07/19/2010 12:52 PM, Mattias Gärtner wrote:
>
> About converting global variables for threads:
> What are the advantages/disadvantages of using ThreadVar versus member 
> variables?
>
I don't see what you are trying to compare here.

Threadvars are addressed by a dedicated register (I suppose a segment 
register with on X86) that is different for each thread ant points to a 
memory area that is dedicated to each thread.

Member variables are addressed using the self pointer of the object and 
thus they are located on the heap and different for each instance of the 
Object but common for all threads.

I suppose the speed difference is very small but the function is very 
different.

If you want an instances of a class for each thread you need to have 
each thread create it's own instance (on the heap) and and hold the 
self-Pointer (the "instance"-variable ) in a threadvar.

-Michael



More information about the fpc-devel mailing list