c++ - std::to_string 线程安全吗?

标签 c++ multithreading c++11 language-lawyer

我希望使用 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.

但是我找不到关于这个主题的任何其他内容,Google 没有提出任何建议,MSDN 也是如此。如果重要的话,我正在使用 Visual Studio 2013。

这个线程安全吗?如果是这样,怎么做?

最佳答案

std::to_string 的行为就像它调用 sprintf ( [string.conversions]/7 ),而 sprintf 的行为取决于全局语言环境,可以通过setlocale(或std::locale::global,内部调用setlocale)进行修改。

[clocale.syn]/2 中的措辞似乎暗示 std::to_string 是线程安全的,因为它不允许 setlocale 引入与 std::to_stringsprintf.

关于c++ - std::to_string 线程安全吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45175559/

相关文章:

c++ - 数组下标和其他类型无效 `int[int]'

java - Java 中使用堆栈的生产者-消费者

multithreading - WCF Operation.Context 不是线程安全的?

ios - 我应该在哪个线程中发送分析数据

C++ 类实现命名空间

c++ - 是否可以仅通过在 C++ 中存储分配的指针地址来分析内存?

c++ - C++ 中没有的头函数

c++ - C++中混合数据类型的算术运算

c++ - 类内成员初始化是否删除赋值运算符?

c++ - 为什么这个boost::asio::tcp::socket可以重复使用?