Struct threadgroup::ThreadGroup [] [src]

pub struct ThreadGroup<T> { /* fields omitted */ }

Holds the collection of threads and the notification channel. All public functions operate on this struct.

Methods

impl<T> ThreadGroup<T>
[src]

[src]

Initialize a group of threads returning T.

Examples

use threadgroup::ThreadGroup;
// spawning and joining require the struct to be mutable, and you'll need to provide type hints.
let mut tg: ThreadGroup<u32> = ThreadGroup::new();

[src]

Spawn a new thread, adding it to the ThreadGroup.

Operates like std::thread::spawn(), but modifies the ThreadGroup instead of returning a JoinHandle.

Examples

use std::time::Duration;
use std::thread::sleep;
use threadgroup::{JoinError, ThreadGroup};
let mut tg: ThreadGroup<u32> = ThreadGroup::new();
tg.spawn::<_,u32>(|| {sleep(Duration::new(0,1000000));1});

[src]

Return count of threads that have been spawn()ed but not yet join()ed.

[src]

Check if there is any thread not yet join()ed.

[src]

Join one thread of the ThreadGroup.

Operates like std::thread::JoinHandle.join(), but picks the first thread that terminates.

Examples

use threadgroup::ThreadGroup;
let mut tg: ThreadGroup<u32> = ThreadGroup::new();
while !tg.is_empty() {
    match tg.join() {
        Ok(ret) => println!("Thread returned {}", ret),
        Err(e) => panic!("Oh noes !"),
    }
}

[src]

Try to join one thread of the ThreadGroup.

Operates like std::thread::JoinHandle.join(), but picks the first thread that terminates and gives up if the timeout is reached.

Examples

use std::time::Duration;
use threadgroup::{JoinError, ThreadGroup};
let mut tg: ThreadGroup<u32> = ThreadGroup::new();
for _ in 0..10 {
   if let Err(JoinError::Timeout) = tg.join_timeout(Duration::new(0,10000)) {
       println!("Still working...");
   }
}