Crates.io | thread_isolated |
lib.rs | thread_isolated |
version | 0.1.1 |
source | src |
created_at | 2015-05-17 01:34:42.224044 |
updated_at | 2015-12-11 23:59:11.698689 |
description | Isolating values allowing access via closures run on an owning thread |
homepage | |
repository | https://github.com/jgallagher/thread_isolated |
max_upload_size | |
id | 2129 |
size | 18,082 |
ThreadIsolated is an experimental library for allowing non-Send
, non-Sync
types to be
shared among multiple threads by requiring that they only be accessed on the thread that
created and owns them. Other threads can indirectly access the isolated data by supplying a
closure that will be run on the owning thread.
The value of ThreadIsolated in a pure Rust application is probably pretty limited (maybe even completely useless). The original motivation for the type is to use Rust on iOS, where it is common to have instances that are only safe to be accessed on the iOS main thread. Using ThreadIsolated gives Rust a way to have types that are only accessed on the iOS main thread but can still be used (albeit indirectly) from threads created in Rust.
In debug builds, ThreadIsolated
will use thread-local storage and perform runtime checks that
all thread access obeys the expected rules. In release builds these checks are not performed.
For an example of ThreadIsolated in pure Rust code, see the test_normal_use
function in the
test
module of src/lib.rs
.
John Gallagher, johnkgallagher@gmail.com
ThreadIsolated is available under the MIT license. See the LICENSE file for more info.