RT-Thread / RT-Thread/rt-thread

关于赋值语句是否具有原子性的讨论

Open
#8,449 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
12.2k
Forks
5.4k
Avg merge
4d 12h
Merged PRs (30d)
40

Description

出发点是看到了在这个PR中的讨论,其中提到的 int32 数据赋值在对齐时本来就是原子的 与我印象中不符,于是查阅了一些资料与各位开发者分享,也希望听听大家的意见。

简单总结一下就是,C/C++中的“赋值”操作并不是原子的,不论从编译器实现上还是语言标准规定上皆是如此,而且变量的地址对齐与否并不影响该结论。
具体可以参考这篇文章 其中详细解释了引起非原子性的原因。

针对rt-thread中大量存在(maybe)的“直接赋值当成原子操作”的行为,是否有必要集中做一次修改?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the discussion in PR #8042 and the linked article on atomic versus non-atomic operations. Review the issue's claim about direct assignments being treated as atomic operations in RT-Thread. The scope and completion criteria are not defined; the issue asks whether a broad change is needed.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, cpp
Domain
embedded-iot, operating-systems
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.