关于STL线程安全和STL调试的问题 [英] question about STL thread-safe and STL debugging

查看:112
本文介绍了关于STL线程安全和STL调试的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个关于STL的问题

I have two questions about STL

1)为什么STL不是线程安全的?是否有任何结构是线程安全的?

1) why STL is not thread-safe? Is there any structure that is thread-safe?

2)如何使用GDB调试STL?在GDB中,我如何打印一个向量?

2) How to debug STL using GDB? In GDB, how can I print a vector?

推荐答案

标准的c ++容器不是线程安全的,水平锁定而不仅仅是容器本身。

The standard c++ containers are not thread safe because you most likely actually want higher level locking than just the containers themselves. In other words you are likely to want two or more operations to be safe together.

例如,如果您有多个运行线程:

For example, if you have multiple threads running:

v.push_back(0);
v.push_back(1);

wont 得到一个交替的0和1的漂亮的矢量,他们可以被混杂。您需要锁定这两个命令以获得所需的内容。

You wont get a nice vector of alternating 0's and 1's, they could be jumbled. You would need to lock around both commands to get what you want.

这篇关于关于STL线程安全和STL调试的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆