Giter VIP home page Giter VIP logo

Comments (3)

Timothy-Liuxf avatar Timothy-Liuxf commented on May 19, 2024

这种情况对象应该声明为 volatile,应该属于第 10746 行和第 6507 行说明的情况吧。

safe-rules/c-cpp-rules.md

Lines 10740 to 10746 in d06e2da

对于内存中的数据,写入之后应被读取,如果出现:
1. 写入后未经读取再次被无条件写入
2. 写入后未经读取即结束了函数的执行
这种写入是无效的,出现这种问题往往意味着逻辑错误或功能不完整。
对象在初始化时的写入和 volatile 型数据可不受本规则限制。

safe-rules/c-cpp-rules.md

Lines 6502 to 6510 in d06e2da

应在适当的场景中合理使用 volatile,否则会导致优化或同步相关的多种问题。
只应在以下场景使用 volatile:
- 与汇编等语言混合处理同一对象
- 信号或中断处理函数处理共享对象
- 对象地址对应外设地址
- 出于安全目的清理内存中的对象
在这些场景中,如果相关对象没有用 volatile 限定,会导致程序和预期不符,volatile 关键字可以保证对象具有稳定的内存地址,任何读取或写入都可以来源于或作用于内存中的实际数据。

from safe-rules.

onionblack avatar onionblack commented on May 19, 2024

也是,那我先关了,我们有一段代码是这样的

while (1) {
  port = 0;
  port = 1;
}

不过port是个对象等号是重载的

from safe-rules.

brotherbeer avatar brotherbeer commented on May 19, 2024

嗯嗯,可以强调一下“存在写入数据之外的副作用时,可不受本规则约束”

from safe-rules.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.