recv() cpu abuse
h04x opened this issue · 4 comments
h04x commented
Hello. I'm new with Rust. 20 recv() uses 40% cpu on my linux box. Is this a known issue?
extern crate bus;
use bus::Bus;
use std::sync::{Arc, Mutex};
use std::thread;
use std::io;
fn main() {
let bus: std::sync::Arc<std::sync::Mutex<bus::Bus<usize>>>
= Arc::new(Mutex::new(Bus::new(10)));
for _ in 0..20 {
let mut rxb = bus.clone().lock().unwrap().add_rx();
thread::spawn(move || loop {
let msg = rxb.recv().unwrap();
});
}
io::stdin().read_line(&mut String::new()).unwrap();
}
total
11909 root 20 0 1029148 1980 1700 S 39.2 0.1 1:01.07 bus_possible_bu
per thread
11926 root 20 0 1029148 1980 1700 R 2.7 0.1 0:00.19 bus_possible_bu
11927 root 20 0 1029148 1980 1700 R 2.7 0.1 0:00.19 bus_possible_bu
11931 root 20 0 1029148 1980 1700 R 2.7 0.1 0:00.19 bus_possible_bu
cpu
model name : Intel(R) Core(TM) i3 CPU 540 @ 3.07GHz
jonhoo commented
Ah, yes, those idle cycles stem from
Line 405 in ec317a2