C ++ boost :: thread并自动锁定容器 [英] C++ boost::thread and automatically locking containers

查看:102
本文介绍了C ++ boost :: thread并自动锁定容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以在访问时自动锁定STL容器,而不必锁定和释放它?

Is there a way to automatically lock an STL container on access, without having to lock and release around it?

推荐答案

当前的C ++标准未提及STL容器的线程安全性。正式而言,STL实现可能是线程安全的,但这是非常不寻常的。如果您的STL实现不是线程安全的,那么您将需要锁定并释放它或寻找其他方式来协调访问。

The currrent C++ standard does not say anything about thread safety for STL containers. Officially it is possible for an STL implementation to be thread safe, but it's very unusual. If your STL implementation is not thread safe, then you will need to "lock and release around it" or find some other way to coordinate access.

您可能会感兴趣英特尔的线程构建模块,其中包括一些类似于STL容器的线程安全容器。

You may be interested in Intel's Threading Building Blocks which includes some thread safe containers similar to STL containers.

这篇关于C ++ boost :: thread并自动锁定容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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