Crate yastl

source ·
Expand description

A library to provide a thread pool that can run scoped and unscoped threads.

It can be used to spawn threads, that are guaranteed to be finished if the scope ends, and thus make it possible to borrow values from the stack (not requiring the 'static bound).

§Example


let pool = Pool::new(4);
let mut list = vec![1, 2, 3, 4, 5];

pool.scoped(|scope| {

    // since the `scope` guarantees that the threads are finished if it drops,
    // we can safely borrow `list` inside here.
    for x in list.iter_mut() {
        scope.execute(move || { *x += 2; });
    }
});

assert_eq!(list, vec![3, 4, 5, 6, 7]);

Structs§

  • A structure providing access to a pool of worker threads and a way to spawn jobs.
  • A scope represents a bunch of jobs that must be finished if this scope is dropped.
  • Provide configuration parameters to the spawned threads like a name prefix.