Hi all,
I have been learning about async programming facilities in Rust for a while and given that I have some decent experience with multithreaded programming (in C++) I fail to see the core advantage. Yes I have seen arguments about everywhere regarding "threads overhead", "threads memory space" yet I don't find them very convincing. My main problem is that you will always need some actual threads to do the blocking/notification part and then somehow communicate that with some shared state (likely a thread safe queue) to the rest of your code. Now this queue already allows the rest of the code to not block and potentially proceed to do something useful and also allows the scaling of consumers up or down. You may have as many consumers as you want up to potentially just one handling any amount of tasks without any additional threads overhead. Let me elaborate with the classic concrete example of "handling many sockets". After reading about it, I find that OS APIs like "epoll" are what allow user code to handle multiple connections without the need to have 1 thread per connection. So in that example one can imagine one thread on the producer side which is monitoring multiple connections via that API and putting any available data into some shared queue with some envelope identifying the source connection and on the consumer side, you can have any number of threads handling the incoming data from that shared queue. Compared to a clear pcp pattern with a shared queue, I see a lot of moving pieces in the Async pattern and as I said I fail to see the main advantage. Perhaps someone can help me out with that?
Thanks
Resources I examined
https://rust-lang.github.io/async-book/01_getting_started/01_chapter.html