[fpc-pascal] String types in a wider perspective
flavio.etrusco at gmail.com
Thu Dec 3 00:04:36 CET 2009
On Tue, Dec 1, 2009 at 2:28 PM, Jonas Maebe <jonas.maebe at elis.ugent.be> wrote:
> On 01 Dec 2009, at 18:03, Luca Olivetti wrote:
>> I always protect multithreaded sting access with a critical section.
>> Do you mean it is not needed?
> The reference counting of ansistrings/... is thread safe. Accessing the characters etc
> still requires explicit synchronization if at least one writer is involved.
(I guess Jonas intended to avoid a complicate answer, but let me
complicate it for you ;-)
... and the AnsiString has refcount = 1. If you access the string
through a by-value parameter or assign it to a temporary variable,
you're safe too. (unless, of course, some screwed code change the
contents of the string in-place - e.g. with a typecast to pchar or
some other pointer)
More information about the fpc-pascal