commit | e78551183b88da48b576a1db59589ad1e212092e | [log] [tgz] |
---|---|---|
author | Martin Geisler <mgeisler@google.com> | Thu Nov 16 12:00:28 2023 +0100 |
committer | Martin Geisler <mgeisler@google.com> | Thu Nov 23 15:56:47 2023 +0100 |
tree | 743cda32af04480b2517ad89df0f0b6cf90acafb | |
parent | 8cd41a9edc2f6aba2ba9dc1b159ff1ade4306479 [diff] |
Import 'fragile' crate Request Document: go/android-rust-importing-crates For CL Reviewers: go/android3p#cl-review For Build Team: go/ab-third-party-imports Bug: 310600229 Change-Id: I2de1ed95cb425cdf4c1d1c6e2d6cc555ddcaa8cc
This library provides wrapper types that permit sending non Send types to other threads and use runtime checks to ensure safety.
It provides the Fragile<T>
, Sticky<T>
and SemiSticky<T>
types which are similar in nature but have different behaviors with regards to how destructors are executed. The Fragile<T>
will panic if the destructor is called in another thread, Sticky<T>
will temporarily leak the object until the thread shuts down. SemiSticky<T>
is a compromise of the two. It behaves like Sticky<T>
but it avoids the use of thread local storage if the type does not need Drop
.
use std::thread; // creating and using a fragile object in the same thread works let val = Fragile::new(true); assert_eq!(*val.get(), true); assert!(val.try_get().is_ok()); // once send to another thread it stops working thread::spawn(move || { assert!(val.try_get().is_err()); }).join() .unwrap();