Crates.io | thread_tryjoin |
lib.rs | thread_tryjoin |
version | 0.3.0 |
source | src |
created_at | 2017-09-28 12:12:43.55335 |
updated_at | 2022-03-10 02:00:21.607572 |
description | Try joining a thread |
homepage | https://github.com/nottxy/thread_tryjoin |
repository | https://github.com/nottxy/thread_tryjoin |
max_upload_size | |
id | 33770 |
size | 24,254 |
It is forked from https://github.com/badboy/thread_tryjoin-rs
Ever needed to wait for a thread to finish, but thought you can still do work until it finishes?
JoinHandle#join()
waits for the thread to finish and is blocking, so it doesn't allow you to try again and again.
Luckily there is a non-portable pthread
API:
pthread_tryjoin_np
This library provides convenient access through a try_join
method on JoinHandle
.
It only works on Linux though.
It uses JoinHandleExt
to get to the underlying pthread_t
handle.
[dependencies]
thread_tryjoin = "0.2"
use std::time::Duration;
use std::thread;
use thread_tryjoin::TryJoinHandle;
let t = thread::spawn(|| { thread::sleep(Duration::from_secs(1)); });
assert!(t.try_join().is_err());
Licensed under either of
at your option.
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.