[fpc-devel] ref count types / threadsave question

Martin Frb lazarus at mfriebe.de
Wed Jan 2 21:46:41 CET 2019

On 02/01/2019 21:22, Benito van der Zander wrote:
> Hi,
> but if another core can do anything to the string, the refcount should 
> already be 2, one for this core and one for the other core, should it not?

// global var
   Foo: String;

// main thread
Foo := getsomestring_with_refcount_1();
TMyThread.Create(false); // not suspended / start

Foo := ''; // de-ref

LocalFoo := Foo; // copy from the global var

If the main threads "Foo:=''; "   is executed ...
- beginning right after fpc_AnsiStr_Incr_Ref in TMyThread did the NIL test
- and finished before the "inclocked"
then the inclocked operates in memory freed in the main thread?

Unless there is some thread save checking each time a global var is 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20190102/e3d58c25/attachment.html>

More information about the fpc-devel mailing list