Arc

Arc<T> 允许通过 Arc::clone 实现共享只读权限:

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Speaker Notes

  • Arc 代表“原子引用计数”,它是使用原子操作的 Rc 的 线程安全版本。
  • Arc<T> implements Clone whether or not T does. It implements Send and Sync if and only if T implements them both.
  • Arc::clone() 在执行原子操作方面有开销,但在此之后,T 便可 随意使用,而没有任何开销。
  • 请警惕引用循环,Arc 不会使用垃圾回收器检测引用循环。
    • std::sync::Weak 对此有所帮助。