scoped_threads

Crates.ioscoped_threads
lib.rsscoped_threads
version0.1.0
sourcesrc
created_at2020-03-29 12:31:41.664061
updated_at2020-03-29 12:31:41.664061
descriptionLightweight, safe and idiomatic scoped threads
homepage
repositoryhttps://github.com/a1phyr/scoped_threads
max_upload_size
id224053
size17,341
Alphyr (a1phyr)

documentation

https://docs.rs/scoped_threads

README

Scoped Threads

Crates.io Docs.rs

Lightweight, safe and idiomatic scoped threads

This crate provides a scoped alternative to std::thread, ie threads that can use non-static data, such as references to the stack of the parent thread. It mimics std's thread interface, so there is nothing to learn to use this crate. There is a meaningful difference, though: a dropped JoinHandle joins the spawned thread instead of detaching it, to ensure that borrowed data is still valid. Additionnally, this crate does not redefine types and functions that are not related to threads being scoped, such as thread::park.

It is lightweight in the sense that it does not uses expensive thread synchronisation such as Arc, locks or channels.

This crate's API is very unlikely to change and can be considered stable, but the crate will only reach 1.0 when unstable feature thread_spawn_unchecked is stabilized.

Why scoped_threads and not crossbeam_utils::scope ?

  • You might not want to bring extra ShardedLocks, CachePadded, etc with your scoped threads

  • The scope function works great but it feels a bit weird and is not flexible

  • Synchronisation primitives such as Arc and Mutex are extensively used and bring a significant overhead

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Commit count: 1

cargo fmt