金庆的专栏

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  423 随笔 :: 0 文章 :: 454 评论 :: 0 Trackbacks
# Why does Rust check borrow even in single thread

(Jin Qing's Column, Aug. 7, 2021)

The Rust book says borrow checking is to prevent data race.
But the borrow checker forbids multiply mutable borrows even in the same thread.
Is there data race in single thread?
Why does the borrow checker forbid it in the same thread?

[The Problem With Single-threaded Shared Mutability](https://manishearth.github.io/blog/2015/05/17/the-problem-with-shared-mutability/)
answers this question.

It gaves 2 cases that shared mutability causes prolem.
One is Rust enum variable, which can has different inner type.
If the inner type changed, the references to the old data would be invalidated.
Another case is Iterator invalidation that the container's change can invalidate the Iterator.


posted on 2021-08-07 16:05 金庆 阅读(195) 评论(0)  编辑 收藏 引用 所属分类: 9. 其它

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理