Article

From:
To:
John May
Subject:
Re: Thread safety with UnicodeString type [Edit]
Newsgroup:
embarcadero.public.cppbuilder.language.cpp

Re: Thread safety with UnicodeString type [Edit]

John wrote:

> Does this mean that reference counting increase/decrease is
> thread-safe (or perhaps atomic operation?)

Yes.  String reference counts are protected by the RTL itself using its own 
locks.

> even though the actual UnicodeString data payload management isn't?

Only one thread can create a new string payload, and it is initialized with 
a reference count of 1.  Only one thread can decrement the reference count 
to 0, and that is the last thread to touch the payload, so that is the thread 
that frees it.

> I did test accessing data from 2 threads when it was being written
> from one and read from another and I do get access violation so it
> doesn't seem thread safe

It depends on what you were doing exactly.  Please show your actual code.

-- Remy Lebeau (TeamB)
FYI: Phrase searches are enclosed in either single or double quotes
 
 
Originally created by
Tamarack Associates
Thu, 14 Nov 2024 17:23:30 UTC
Copyright © 2009-2024
HREF Tools Corp.