<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body smarttemplateinserted="true">
<div id="smartTemplate4-template">Hi,<br>
</div>
<div><br>
</div>
<div>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?<br>
</div>
<div><br>
</div>
<div>UniqueString has such a test:<br>
<p>Function fpc_ansistr_Unique(Var S : Pointer): Pointer;
[Public,Alias : 'FPC_ANSISTR_UNIQUE']; compilerproc; inline;<br>
{<br>
Make sure reference count of S is 1,<br>
using copy-on-write semantics.<br>
}<br>
begin<br>
pointer(result) := pointer(s);<br>
If Pointer(S)=Nil then<br>
exit;<br>
if PAnsiRec(Pointer(S)-AnsiFirstOff)^.Ref<>1 then<br>
result:=fpc_truely_ansistr_unique(s);<br>
end; <br>
</p>
<br>
<br>
Bye,<br>
Benito </div>
<br>
<div class="moz-cite-prefix">Am 02.01.19 um 20:14 schrieb Jonas
Maebe:<br>
</div>
<blockquote type="cite"
cite="mid:0a9dc481-79dd-5a23-d2d2-a234a79878dd@freepascal.org">On
02/01/19 20:08, Martin wrote:
<br>
<blockquote type="cite">If a local string var has a refcount of 1,
then it can not be accessed by any other thread. Therefore it
needs no lock for decreasing the ref.
<br>
</blockquote>
<br>
You would need a full memory barrier before checking whether the
reference count is one, otherwise it could have been increased to
two by another thread on another core quite a while ago without
that change being already visible on the current core. This would
probably slow down things much more than any potential gain from
not performing the atomic decrement.
<br>
<br>
<br>
Jonas
<br>
_______________________________________________
<br>
fpc-devel maillist - <a class="moz-txt-link-abbreviated" href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a>
<br>
<a class="moz-txt-link-freetext" href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</a>
<br>
</blockquote>
</body>
</html>