Crates.io | borrowed-thread |
lib.rs | borrowed-thread |
version | 0.1.3 |
source | src |
created_at | 2018-11-16 17:41:59.24287 |
updated_at | 2018-11-16 18:04:37.110917 |
description | thread-safe way to pass borrow to thread::spawn |
homepage | https://github.com/Riey/borrowed-thread |
repository | https://github.com/Riey/borrowed-thread |
max_upload_size | |
id | 97088 |
size | 6,762 |
thread-safe way to pass borrow to thread::spawn
NEED nightly rust!
test bench::bench_borrowed_thread ... bench: 18,902 ns/iter (+/- 690)
test bench::bench_std_thread ... bench: 18,859 ns/iter (+/- 684)
use borrowed_thread;
let mut owned = "ABC".to_owned();
let borrowed_handle = borrowed_thread::spawn(|| {
owned.push('D');
0
});
let ret = borrowed_handle.join().expect("join err");
assert_eq!(0, ret);
assert_eq!("ABCD", owned);
use borrowed_thread;
let owned = "ABC".to_owned();
let borrowed_handle = borrowed_thread::spawn(|| {
assert_eq!("ABC", owned);
0
});
let ret = borrowed_handle.join().expect("join err");
assert_eq!(0, ret);
let mut owned = "ABC".to_owned();
let borrowed_handle = borrowed_thread::spawn(|| {
owned.push('D');
0
});
// this will cause panic!
drop(borrowed_handle);
assert_eq!("ABCD", owned);