Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upErgonomics with handling dropping RegionBuffer early. #1
Comments
Aaronepower
changed the title
Unsoundness with dropping RegionBuffer early.
Ergonomics with handling dropping RegionBuffer early.
Dec 9, 2018
This comment has been minimized.
This comment has been minimized.
dtolnay
commented
Dec 9, 2018
|
614de6b does not fix the bug because it only kills the thread holding ownership of the RegionBuffer, not any other threads that may be holding elements at the time that the RegionBuffer is dropped. The following still triggers a core dump or segfault as of region_buffer 0.1.4. use region_buffer::region_buffer;
use std::sync::{Arc, Mutex};
use std::thread;
fn main() {
let el = Arc::new(Mutex::new(None));
let el2 = el.clone();
let thread = thread::spawn(move || {
let rb = region_buffer!["Hello".to_owned()];
*el2.lock().unwrap() = Some(rb.get_mut(0));
});
thread.join().unwrap_err();
let mut s = el.lock().unwrap();
s.as_mut().unwrap().push('x');
println!("{:?}", s);
} |
This comment has been minimized.
This comment has been minimized.
dtolnay
commented
Dec 9, 2018
|
Here is a simpler repro on a single thread. use region_buffer::region_buffer;
use std::sync::Mutex;
use std::panic;
fn main() {
let el = Mutex::new(None);
let _ = panic::catch_unwind(|| {
let rb = region_buffer!["Hello".to_owned()];
*el.lock().unwrap() = Some(rb.get_mut(0));
});
let mut s = el.lock().unwrap();
s.as_mut().unwrap().push('x');
println!("{:?}", s);
} |
This comment has been minimized.
This comment has been minimized.
|
fixed by #5 |
Aaronepower
closed this
Dec 9, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Aaronepower commentedDec 9, 2018
•
edited
The following code should panic, right now it either causes a coredump or if the program is short enough nothing at all.
EDIT: I've published a workaround that will now cause this code to panic by adding a
Dropimplementation to theRegionBuffertype. I'm going to keep this open to instead track alternatives to solving this issue.