[fpc-pascal] Re: How to initialize thread vars?

Michael Van Canneyt michael at freepascal.org
Thu Sep 4 15:01:44 CEST 2008



On Thu, 4 Sep 2008, "Vinzent Höfler" wrote:

> Hi,
> 
> > I think that thread variables are automatically initialized to zero. So
> > you just need to use them in such a way that zero is the desired start
> > value.
> 
> Hmm, yes. I just checked the sourcecode and indeed, for Win32 and Unix at least the threadvars are indeed initialized to zero. That would fit nicely here. ;)
> 
> If any of the developers could confirm, whether this is guaranteed semantics or was just a sane choice by the implementor? Because the documentation reads quite a bit differently:
> 
> <http://www.freepascal.org/docs-html/ref/refse22.html#x53-590004.4> states:
> 
> "Note that the copy is made with the original value of the variable, not with the value of the variable at the time the thread is started."
> 
> Which doesn't make too much sense to me considering that I can't initialize thread vars at all (compiler complains: 'Cannot initialize variables declared as threadvar'). So what would this "original value" be (besides the obvious zero - which is the default value for all global variables)?

The original value is zero.

Michael.


More information about the fpc-pascal mailing list