CRITICAL_SECTION的set和get单bool值 [英] CRITICAL_SECTION for set and get single bool value

查看:148
本文介绍了CRITICAL_SECTION的set和get单bool值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在编写复杂的,并认为我用得多 CRITICAL_SECTION

据我所知,有一些类型的原子操作,那些始终没有任何硬件或软件中断执行。

我要检查,如果我理解正确的一切。


  • 要设置或获取原子值,我们不需要 CRITICAL_SECTION ,因为这样做不会有中断。

  • 布尔是原子的。

因此​​,有我的陈述,要问,如果他们是正确的,如果他们也都是正确的,什么类型的变量,也可以设置或不 CRITICAL_SECTION ?<得到/ p>

P上。秒。我谈论获取或设置的单个值每方法,而不是两个,不是五个,而是一个。


解决方案

  1. 您不需要锁轮原子数据,但是在内部,他们可能会锁定。注意:例如,C ++ 11的的std ::原子有一个 is_lock_free 功能。

  2. 布尔可能不是原子。见<一href=\"http://stackoverflow.com/questions/14624776/can-a-bool-read-write-operation-be-not-atomic-on-x86\">here和<一个href=\"http://stackoverflow.com/questions/16320838/when-do-i-really-need-to-use-atomicbool-instead-of-bool\">here

now writing complicated class and felt that I use to much CRITICAL_SECTION.

As far as I know there are atomic operations for some types, that are always executed without any hardware or software interrupt.

I want to check if I understand everything correctly.

  • To set or get atomic value we don't need CRITICAL_SECTION because doing that there won't be interrupts.
  • bool is atomic.

So there are my statements, want to ask, if they are correct, also if they are correct, what types variables may be also set or get without CRITICAL_SECTION?

P. S. I'm talking about getting or setting one single value per method, not two, not five, but one.

解决方案

  1. You don't need locks round atomic data, but internally they might lock. Note for example, C++11's std::atomic has a is_lock_free function.
  2. bool may not be atomic. See here and here

这篇关于CRITICAL_SECTION的set和get单bool值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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