<div dir="ltr"><div dir="ltr"><div>Busy working on threading and TLS, started with a stand-alone unit along the lines of cthreads and using OS memory allocation for storing the TLS blocks. After initializing (calling SysInitMultithreading) a block of memory is allocated and threadvars copied.  However there appears to be a two byte offset in the location of the threadvars after relocating them, see test and output below.<br></div><div><br></div><div>program testTLS;<br></div><div>uses fthreads;</div><div><br></div><div>threadvar<br>  x, y, z: uint32;<br><br>begin<br>  x := $11ABCDEF; <br>  y := $99887766;<br>  z := $55443322;<br>  writeln('Initial x location: ', HexStr(@x), '. Value = ', HexStr(pointer(x)));<br>  writeln('Initial y location: ', HexStr(@y), '. Value = ', HexStr(pointer(y)));<br>  writeln('Initial z location: ', HexStr(@z), '. Value = ', HexStr(pointer(z)));<br><br>  writeln('Initializing threads...');<br>  fthreads.SysInitMultithreading;<br><br>  writeln('Current x location: ', HexStr(@x), '. Value = ', HexStr(pointer(x)));<br>  writeln('Current y location: ', HexStr(@y), '. Value = ', HexStr(pointer(y)));<br>  writeln('Current z location: ', HexStr(@z), '. Value = ', HexStr(pointer(z)));<br><br>  repeat  until false;<br>end.<br></div><div><br></div><div>Output:</div><div>Initial x location: 3FFB268C. Value = 11ABCDEF<br>Initial y location: 3FFB2694. Value = 99887766<br>Initial z location: 3FFB269C. Value = 55443322<br>Initializing threads...<br>Current x location: 3FFB7E12. Value = CDEF0000<br>Current y location: 3FFB7E16. Value = 776611AB<br>Current z location: 3FFB7E1A. Value = 33229988<br><br></div><div>This is a little endian system so the output can be explained by shifting the pointer references back (before the actual location) by two bytes.</div><div><br></div><div>Somewhere between how FPC presents the pointers to the thread vars, how the RTL access the pointers and how the new implementation allocates and presents the storage pointer there appears to be a mismatch.  One thing I would like to investigate is how the compiler packs the thread vars and how the relocated data is interpreted by the RTL.  </div><div><br></div><div>Any hints on what to look for?</div><div><br></div><div>Attached the fthreads unit for reference.</div><div><br></div><div>Best regards,</div><div>Christo</div></div></div>