<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.6001.18099" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>I thought about usings Objects in Multithreaded
objects and had a look at astrings.inc to get some inspiration.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>I had this problem:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>one global string</FONT></DIV>
<DIV><FONT face=Arial size=2>two threads</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>lets say, both threads set the string to nil. I
belive there is such a case:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Thread 1 checks for S=Nil an fpc_ansistr_decr_ref
(svn version, 15.9.)</FONT></DIV>
<DIV><FONT face=Arial size=2>Threadswitch to Thread 2</FONT></DIV>
<DIV><FONT face=Arial size=2>Thread 2 checks runs the whole procedure,
decrements reference count to zero (only one reference (global)) and calls
DisposeAnsiString</FONT></DIV>
<DIV><FONT face=Arial size=2>* Evil case * Memory is reallocated by someone else
in Thread2 and filled with some nonsense</FONT></DIV>
<DIV><FONT face=Arial size=2>Threadswitch to Thread 1</FONT></DIV>
<DIV><FONT face=Arial size=2>Thread 1 runs the rest of fpc_ansistr_decr_ref,
assume integer at S-Firstoff is >0 we will suddenly decrement an integer
inside a foreign memory block</FONT></DIV>
<DIV><FONT face=Arial size=2>* Very evil case* Integer was =1, we even free the
memory again. (with many following problems and exceptions)</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>I really hope i am wrong. If i am not, my current
solution is to put a mutex around fpc_ansistr_decr_ref, but i know that this
solution is slow.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>I am trying to find a better
solution.</FONT></DIV></BODY></HTML>