-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make
AtomicBox<T>
non-Sync
when T
is non-Send
.
Fixes a soundness bug reported by @geeklint. Closes #5. This breaks API compatibility only for programs that are doing something very unsafe, but a version bump seems appropriate anyway.
- Loading branch information
1 parent
5bda33d
commit 0775644
Showing
5 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
extern crate atomicbox; | ||
|
||
use atomicbox::AtomicBox; | ||
use std::rc::Rc; | ||
|
||
fn main() { | ||
let rc_main = Rc::new("Hello, world!"); | ||
let rc_other = Rc::clone(&rc_main); | ||
|
||
let abox = AtomicBox::new(Box::new(rc_other)); | ||
let handle = std::thread::spawn(move || { | ||
//~^ ERROR `Rc<&str>` cannot be sent between threads safely | ||
let value = *abox.into_inner(); | ||
println!("Other thread: {:?}", value); | ||
}); | ||
handle.join().unwrap(); | ||
println!("Main Thread: {:?}", rc_main); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#![allow(clippy::field_reassign_with_default)] | ||
|
||
// Copied from <https://lib.rs/crates/compiletest_rs>. | ||
|
||
extern crate compiletest_rs as compiletest; | ||
|
||
use std::path::PathBuf; | ||
|
||
fn run_mode(mode: &'static str) { | ||
let mut config = compiletest::Config::default(); | ||
|
||
config.mode = mode.parse().expect("Invalid mode"); | ||
config.src_base = PathBuf::from(format!("tests/{}", mode)); | ||
config.target_rustcflags = Some("-L target/debug".to_string()); | ||
config.link_deps(); // Populate config.target_rustcflags with dependencies on the path | ||
config.clean_rmeta(); // If your tests import the parent crate, this helps with E0464 | ||
|
||
compiletest::run_tests(&config); | ||
} | ||
|
||
#[test] | ||
fn compile_test() { | ||
run_mode("compile-fail"); | ||
} |