hniksic / sendable Goto Github PK
View Code? Open in Web Editor NEWWrapper around Rc safe to send to a different thread
License: Apache License 2.0
Wrapper around Rc safe to send to a different thread
License: Apache License 2.0
Hi! I believe I have spotted some unsoundness in the SendRc implementation, or more specifically this line of PostSend
.
This is the reproducer I came up with, it (usually) doesn't actually behave unsoundly but it does show that there is a reference to the same RefCell on 2 different threads.
use std::{
cell::RefCell,
sync::{Arc, Barrier},
};
use sendable::SendRc;
fn main() {
let mut a = SendRc::new(RefCell::new(1));
let mut b = SendRc::clone(&a);
let mut pre_send = SendRc::pre_send();
pre_send.disable(&mut a);
pre_send.disable(&mut b);
let mut post_send = pre_send.ready();
post_send.enable(&mut a);
let a_inner = &*a;
let a_barrier = Arc::new(Barrier::new(2));
let b_barrier = Arc::clone(&a_barrier);
std::thread::spawn(move || {
post_send.enable(&mut b);
drop(post_send);
let b_inner = &*b;
b_barrier.wait();
println!("{}", b_inner.borrow_mut())
});
a_barrier.wait();
println!("{}", a_inner.borrow_mut());
}
The idea is to exploit the line I linked above by re-enabling one copy of the SendRc
on the original thread, before sending the other copy to another thread.
More generally, I think the idea behind the library is sound, and I didn't spot any other unsoundness but I'm not very confident in that.
Am I correct to say that it's difficult to prevent this from panicking when the SendRC is being dropped as the drop could be initiated from any thread ?!?
I'm struggling to find a good pattern to ensure that the drop thread has ownership of the SendRC when drop is called.
Do you have any thoughts on this ?
Hi,
it seems there is no sendable Weak reference?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.