[英]Thread safety of AnsiString reference counting mechanism
My question is about AnsiString in Borland C++Builder 6.0我的问题是关于 Borland C++Builder 6.0 中的 AnsiString
As you know, VCL's AnsiString uses reference counting.如您所知,VCL 的 AnsiString 使用引用计数。
Is that reference counting thread safe?那个引用计数线程安全吗?
For example, suppose we have std::queue<AnsiString> asq;
例如,假设我们有
std::queue<AnsiString> asq;
We push an AnsiString value in that queue in thread#1, and then we do asq.pop()
in thread#2.我们在线程#1 的那个队列中推送一个 AnsiString 值,然后我们在线程#2 中执行
asq.pop()
。 (The access to asq
itself is synchronized.) Strings are not modified. (对
asq
本身的访问是同步的。)不修改字符串。
Is it possible I will have a memory leak when AnsiString's destructor is called when using AnsiString(s) that way?当以这种方式使用 AnsiString 时调用 AnsiString 的析构函数时,我是否可能会发生 memory 泄漏?
Yes, the refcount is thread-safe.是的,引用计数是线程安全的。 The RTL places a lock on the refcount whenever it is being incremented and decremented.
无论何时递增和递减,RTL 都会在 refcount 上放置一个锁。 There will not be any memory leak in the scenario you describe.
在您描述的场景中,不会有任何 memory 泄漏。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.