File: README.md

package info (click to toggle)
rust-scoped-threadpool 0.1.9-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 104 kB
  • sloc: makefile: 2
file content (53 lines) | stat: -rw-r--r-- 1,436 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
scoped-threadpool-rs
==============

[![Travis-CI Status](https://travis-ci.org/Kimundi/scoped-threadpool-rs.png?branch=master)](https://travis-ci.org/Kimundi/scoped-threadpool-rs)

A library for scoped and cached threadpools.

For more details, see the [docs](http://kimundi.github.io/scoped-threadpool-rs/scoped_threadpool/index.html).

# Getting Started

[scoped-threadpool-rs is available on crates.io](https://crates.io/crates/scoped_threadpool).
Add the following dependency to your Cargo manifest to get the latest version of the 0.1 branch:
```toml
[dependencies]

scoped_threadpool = "0.1.*"
```

To always get the latest version, add this git repository to your
Cargo manifest:

```toml
[dependencies.scoped_threadpool]
git = "https://github.com/Kimundi/scoped-threadpool-rs"
```
# Example

```rust
extern crate scoped_threadpool;
use scoped_threadpool::Pool;

fn main() {
    // Create a threadpool holding 4 threads
    let mut pool = Pool::new(4);

    let mut vec = vec![0, 1, 2, 3, 4, 5, 6, 7];

    // Use the threads as scoped threads that can
    // reference anything outside this closure
    pool.scoped(|scoped| {
        // Create references to each element in the vector ...
        for e in &mut vec {
            // ... and add 1 to it in a seperate thread
            scoped.execute(move || {
                *e += 1;
            });
        }
    });

    assert_eq!(vec, vec![1, 2, 3, 4, 5, 6, 7, 8]);
}
```