• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

examples/H03-May-2022-2219

script/H03-May-2022-43

src/H03-May-2022-1,477892

.cargo-checksum.jsonH A D03-May-202289 11

.cargo_vcs_info.jsonH A D01-Jan-197074 65

.gitignoreH A D14-Aug-201828 43

.travis.ymlH A D08-Jan-2019663 3426

Cargo.tomlH A D01-Jan-19701,004 2220

Cargo.toml.orig-cargoH A D27-Aug-2019496 1614

LICENSEH A D14-Aug-20181.1 KiB2117

README.mdH A D08-Jan-20191.4 KiB6548

README.md

1spin-rs
2===========
3
4[![Build Status](https://travis-ci.org/mvdnes/spin-rs.svg)](https://travis-ci.org/mvdnes/spin-rs)
5[![Crates.io version](https://img.shields.io/crates/v/spin.svg)](https://crates.io/crates/spin)
6[![docs.rs](https://docs.rs/spin/badge.svg)](https://docs.rs/spin/)
7
8This Rust library implements a simple
9[spinlock](https://en.wikipedia.org/wiki/Spinlock), and is safe for `#[no_std]` environments.
10
11Usage
12-----
13
14Include the following code in your Cargo.toml
15
16```toml
17[dependencies.spin]
18version = "0.5"
19```
20
21Example
22-------
23
24When calling `lock` on a `Mutex` you will get a reference to the data. When this
25reference is dropped, the lock will be unlocked.
26
27```rust
28extern crate spin;
29
30fn main()
31{
32    let mutex   = spin::Mutex::new(0);
33    let rw_lock = spin::RwLock::new(0);
34
35    // Modify the data
36    {
37      let mut data = mutex.lock();
38      *data = 2;
39      let mut data = rw_lock.write();
40      *data = 3;
41    }
42
43    // Read the data
44    let answer =
45    {
46      let data1 = mutex.lock();
47      let data2 = rw_lock.read();
48      let data3 = rw_lock.read(); // sharing
49      (*data1, *data2, *data3)
50    };
51
52    println!("Answers are {:?}", answer);
53}
54```
55
56To share the lock, an `Arc<Mutex<T>>` may be used.
57
58Remarks
59-------
60
61The behaviour of these lock is similar to their namesakes in `std::sync`. they
62differ on the following:
63
64 - The lock will not be poisoned in case of failure;
65