位集单个位线程对于每个单个线程一次写入是否安全? [英] Are bitset individual bits thread safe for per individual thread to write into at a single time?

查看:70
本文介绍了位集单个位线程对于每个单个线程一次写入是否安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我们是否使用 catchline ,甚至可以同时使用64位字长位集中的单个位?假设我有10个线程,每个线程都有 threadId 。所有线程都可以同时设置 bits [threadId] = value 吗?

I wonder if we operate on a catchline or even 64bit word sizes can I concurrently operate on individual bits in a bitset? Say I have 10 threads, each has threadId. Can all threads concurrently set bits[threadId] = value?

推荐答案

std :: bitset :: operator []

数据竞争

可以访问该位集(const和非const版本都不能修改容器)。
非常量版本返回的引用可用于访问或修改位集中的位。请注意,修改单个位可能会影响不确定的位集中其他位的数量,从而导致不同位的并发访问/修改不是线程安全的。

The bitset is accessed (neither the const nor the non-const versions modify the container). The reference returned by the non-const version can be used to access or modify the bits in the bitset. Notice that modifying a single bit may have effects on an undetermined number of other bits in the bitset, thus rendering concurrent access/modification of different bits not thread-safe.

这篇关于位集单个位线程对于每个单个线程一次写入是否安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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