From 06451fbab1b59116c8e0634472fb9e35fdaee48e Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Tue, 7 Jun 2016 21:11:23 -0700 Subject: Add named thread for pty reader --- src/main.rs | 4 +++- src/util.rs | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/util.rs diff --git a/src/main.rs b/src/main.rs index 2fc11f60..faf397c5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,6 +28,7 @@ mod meter; mod tty; mod ansi; mod term; +mod util; use std::sync::mpsc::TryRecvError; use std::collections::HashMap; @@ -42,6 +43,7 @@ use text::FontDesc; use grid::Grid; use term::Term; use meter::Meter; +use util::thread; #[derive(Debug, Eq, PartialEq, Copy, Clone, Default)] pub struct Rgb { @@ -128,7 +130,7 @@ fn main() { } let (chars_tx, chars_rx) = ::std::sync::mpsc::channel(); - ::std::thread::spawn(move || { + thread::spawn_named("TTY Reader", move || { for c in reader.chars() { let c = c.unwrap(); chars_tx.send(c).unwrap(); diff --git a/src/util.rs b/src/util.rs new file mode 100644 index 00000000..0a3de227 --- /dev/null +++ b/src/util.rs @@ -0,0 +1,12 @@ +/// Threading utilities +pub mod thread { + /// Like `thread::spawn`, but with a `name` argument + pub fn spawn_named(name: S, f: F) -> ::std::thread::JoinHandle + where F: FnOnce() -> T, + F: Send + 'static, + T: Send + 'static, + S: Into + { + ::std::thread::Builder::new().name(name.into()).spawn(f).expect("thread spawn works") + } +} -- cgit