Article

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

Re: Thread safety with UnicodeString type [Edit] [Edit]

John wrote:

> The example below works without errors (when Button1 is clicked that
> is). But if you don't wrap shared variable (SupposedToBeThreadSafe) in
> ProtectWrite and ProtectRead functions (as in commented lines) you
> should get errors above.

Assigning a string to another string is thread-safe.  Concatenating a string 
to another string is not.  Concatenation requires multiple steps (reading 
string lengths, allocating memory, copying string characters), and the strings 
being concatenated could be modified by another thread while the concatenation 
is still in progress.  That is why you get crashes when using un-protected 
access.

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