borrowed-thread 0.1.3

thread-safe way to pass borrow to thread::spawn
Documentation
  • Coverage
  • 0%
    0 out of 6 items documented0 out of 5 items with examples
  • Size
  • Source code size: 6.39 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.32 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 11s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Riey/borrowed-thread
    0 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Riey

borrowed-thread

thread-safe way to pass borrow to thread::spawn

NEED nightly rust!

benchmark

test bench::bench_borrowed_thread ... bench: 18,902 ns/iter (+/- 690)

test bench::bench_std_thread ... bench: 18,859 ns/iter (+/- 684)

examples

with &mut

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);

with &

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);

panic when drop without join

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);