I have a worker thread implemented something like this:
impl WorkerThread {
fn new() -> Self {
let (main_sender, thread_receiver) = crossbeam_channel::unbounded();
let (thread_sender, main_receiver) = crossbeam_channel::unbounded();
let _ = thread::spawn(move || loop {
if let Ok(s) = thread_receiver.recv() {
let result = do_work();
thread_sender.send(result).unwrap();
}
});
Self {
main_sender,
main_receiver,
}
}
}
Is this infinite loop
considered a Busy Waiting?
The documentation for the crossbeam_channel::Receiver::recv
says:
Blocks the current thread until a message is received or the channel is empty and disconnected.
But what does this Blocks the current thread
mean?
On my Ubuntu, I looked with htop
on the CPU load and with this blocking call, I saw that only one core (the main thread) was busy. But if I replace recv()
with non-blocking try_recv()
the htop
shows that my second core load increases up to 100%.
Can I assume the identical behavior on every platform (Linux, Mac, Windows, etc)? Or is it how my particular systems scheduler works?