c – 构造不同的元素时,’std :: allocator :: construct’是否是线程安全的?

weixin_38083228 2019-09-12 11:36:35
c标准是否保证使用std :: allocator构造不同的元素是线程安全的?例如: // main thread std::allocator<T> alloc; auto *p = alloc.allocate(2); // thread1 alloc.construct(p); // thread2 alloc.construct(p + 1) 另外,对于不同的元素,std :: allocator :: destroy是否是线程安全的? 谢谢!
...全文
45 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_38090696 2019-09-12
  • 打赏
  • 举报
回复
20.7.9.1 allocator members [allocator.members] 1 Except for the destructor, member functions of the default allocator shall not introduce data races (1.10) as a result of concurrent calls to those member functions from different threads. Calls to these functions that allocate or deallocate a particular unit of storage shall occur in a single total order, and each such deallocation call shall happen before the next allocation (if any) in this order. 所以是的,在std :: allocator< T>上构造和销毁的并发调用.保证是线程安全的.

433

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧