#How does rx.recv() work without constantly looping over and over?
15 messages · Page 1 of 1 (latest)
rx.recv() blocks the thread, then how does it know when the Sender has sent a signal?
The answer probably involves some synchronization primitives, but it ultimately bottoms out to "the sender tells the OS to unblock the receiving thread"
is it possible to implement something similar to rx.recv() that tells the OS to unblock the thread
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
I'm trying to tail a log file, immediately prints out the message when the file gets updated
You probably want a file watcher, I think?
rn I'm loop this f.metadata().unwrap().len(); to see if the file is updated
which uses a lot of cpu
There's better APIs than that, but they're OS-specific.
Find yourself a file watcher crate instead, it does that for you
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
thanks, I will try it out