-
Notifications
You must be signed in to change notification settings - Fork 5
/
0037-concread.rs
60 lines (51 loc) · 1.63 KB
/
0037-concread.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*!
```rudra-poc
[target]
crate = "concread"
version = "0.2.5"
indexed_version = "0.1.18"
[report]
issue_url = "https://github.com/kanidm/concread/issues/48"
issue_date = 2020-11-13
rustsec_url = "https://github.com/RustSec/advisory-db/pull/532"
rustsec_id = "RUSTSEC-2020-0092"
[[bugs]]
analyzer = "SendSyncVariance"
bug_class = "SendSyncVariance"
bug_count = 2
rudra_report_locations = [
"src/cache/arc/mod.rs:153:1: 153:88",
"src/cache/arc/mod.rs:154:1: 154:88",
]
```
!*/
#![forbid(unsafe_code)]
use concread::arcache::ARCache;
use std::rc::Rc;
use std::sync::Arc;
fn main() {
let non_sync_item = Rc::new(0); // neither `Send` nor `Sync`
assert_eq!(Rc::strong_count(&non_sync_item), 1);
let cache = ARCache::<i32, Rc<u64>>::new_size(5, 5);
let mut writer = cache.write();
writer.insert(0, non_sync_item);
writer.commit();
let arc_parent = Arc::new(cache);
let mut handles = vec![];
for _ in 0..5 {
let arc_child = arc_parent.clone();
let child_handle = std::thread::spawn(move || {
let reader = arc_child.read(); // new Reader of ARCache
let smuggled_rc = reader.get(&0).unwrap();
for _ in 0..1000 {
let _dummy_clone = Rc::clone(&smuggled_rc); // Increment `strong_count` of `Rc`
// When `_dummy_clone` is dropped, `strong_count` is decremented.
}
});
handles.push(child_handle);
}
for handle in handles {
handle.join().expect("failed to join child thread");
}
assert_eq!(Rc::strong_count(arc_parent.read().get(&0).unwrap()), 1);
}