简体   繁体   English

std :: to_string线程安全吗?

[英]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 on std::locale for formatting purposes, and therefore concurrent calls to std::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_stringsprintf的数据竞争。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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