I use Linux's mount(2)
function in a single-threaded process. But mounting of devices devices like CD-ROM may take a while (worst I've seen is 40 seconds!), as it will ponder a little, spin up the disk, and only then will mount the filesystem. This may block the process from processing other events for considerable time.
I cannot seem to find a way to mount a filesystem in a non-blocking way. Is there a way to mount a filesystem asynchronously without multi-threading or forking?
Knowing whether the action is complete is not an issue for me as I already read kernel uevents in the same thread.
No. Without firing up another thread or fork()
ing, you have to wait for mount()
to return.
If you want to do it in a single threaded manner, you can manually execute the mount command and background it and poll for completion using select() or something. However, this is hackish and not very different from forking and calling mount() within your program.
Also worth noting is that I've experienced mount() blocking an entire process (and associated threads), so for true asynchronous behavior, forking is probably the way to go.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With