简体   繁体   中英

Thread safety of AnsiString reference counting mechanism

My question is about AnsiString in Borland C++Builder 6.0
As you know, VCL's AnsiString uses reference counting.
Is that reference counting thread safe?
For example, suppose we have std::queue<AnsiString> asq;
We push an AnsiString value in that queue in thread#1, and then we do asq.pop() in thread#2. (The access to asq itself is synchronized.) Strings are not modified.
Is it possible I will have a memory leak when AnsiString's destructor is called when using AnsiString(s) that way?

Yes, the refcount is thread-safe. The RTL places a lock on the refcount whenever it is being incremented and decremented. There will not be any memory leak in the scenario you describe.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM