#How does rx.recv() work without constantly looping over and over?

15 messages · Page 1 of 1 (latest)

keen jackal
#
        match rx.try_recv() { }
}``` uses crazy amount of CPU which is reasonable, because it's looping.
#

rx.recv() blocks the thread, then how does it know when the Sender has sent a signal?

faint flicker
keen jackal
#

is it possible to implement something similar to rx.recv() that tells the OS to unblock the thread

faint flicker
#

You may want to look into one or more of

  • mutexes
  • semaphores
  • barriers
  • condvars
  • thread parking/unparking
#

Unless you want to implement those things, in which case pick an OS, there's APIs for it

keen jackal
#

I'm trying to tail a log file, immediately prints out the message when the file gets updated

faint flicker
#

You probably want a file watcher, I think?

keen jackal
#

rn I'm loop this f.metadata().unwrap().len(); to see if the file is updated

#

which uses a lot of cpu

faint flicker
#

There's better APIs than that, but they're OS-specific.

Find yourself a file watcher crate instead, it does that for you

arctic gustBOT
#

Cross-platform filesystem notification library

Version

5.0.0

Downloads

8 977 329

azure shard
#

This is the popular file watcher it has multiple watching methods you can use depending on the use case

#

For example it will use OS based notifications if available, but fallback to polling the file if not

keen jackal
#

thanks, I will try it out