[英]Is std::to_string thread safe?
I am looking to convert integer types to string using std::to_string
, but I saw this paragraph: 我期待使用
std::to_string
将整数类型转换为字符串,但我看到了这一段:
std::to_string
relies onstd::locale
for formatting purposes, and therefore concurrent calls tostd::to_string
from multiple threads may result in partial serialization of calls.std::to_string
依赖于std::locale
进行格式化,因此从多个线程对std::to_string
并发调用可能导致调用的部分序列化。
But I couldn't find anything else on this topic, Google didn't come up wit anything, as did MSDN. 但是我找不到关于这个主题的任何其他内容,谷歌没有像MSDN那样提出任何问题。 I am using Visual Studio 2013 if it matters.
如果重要的话,我正在使用Visual Studio 2013。
Is this thread safe? 这个线程安全吗? If so, how?
如果是这样,怎么样?
std::to_string
behaves as if it calls sprintf
( [string.conversions]/7 ), and the behavior of sprintf
depends on the global locale, which can be modified by setlocale
(or by std::locale::global
, which internally calls setlocale
). std::to_string
就像调用sprintf
( [string.conversions] / 7 )一样, sprintf
的行为取决于全局语言环境,可以通过setlocale
(或std::locale::global
,内部修饰)修改调用setlocale
)。
The wording in [clocale.syn]/2 seems to imply that std::to_string
is thread safe, because it does not allow setlocale
to introduce a data race with std::to_string
or sprintf
. [clocale.syn] / 2中的措辞似乎暗示
std::to_string
是线程安全的,因为它不允许setlocale
引入带有std::to_string
或sprintf
的数据竞争。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.