当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Rust Arc.strong_count用法及代码示例


本文简要介绍rust语言中 std::sync::Arc.strong_count 的用法。

用法

pub fn strong_count(this: &Arc<T>) -> usize

获取指向此分配的强 (Arc) 指针的数量。

安全性

这种方法本身是安全的,但正确使用它需要格外小心。另一个线程可以随时更改强计数,包括可能在调用此方法和对结果进行操作之间。

例子

use std::sync::Arc;

let five = Arc::new(5);
let _also_five = Arc::clone(&five);

// This assertion is deterministic because we haven't shared
// the `Arc` between threads.
assert_eq!(2, Arc::strong_count(&five));

相关用法


注:本文由纯净天空筛选整理自rust-lang.org大神的英文原创作品 std::sync::Arc.strong_count。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。