Ever since I started doing programming, I was always driven to consensus that thread blocking is bad – there are operations that are intrinsically asynchronous and we should create code that respects this condition. So that’s how we get to the callback hell, that’s how Promise API gets invented, that’s how Rx appears, that’s how async-await was popularized via C#, etc.
However, my language of choice has very poor support for async-await and coroutines, and I was wondering – what are the consequences of writing an iOS or Android app in a synchronous fashion by converting all asynchronous operations into synchronous via blocking?
My rationale is:
- I will manage my threads very carefully, never do stuff on main thread, always will context switch accordingly and as little as possible
- My app is not a 1000 requests-per-second server, and at any given moment there is no more than 2 asynchronous I/O operations, so it’s not like I’m gonna run out of threads
So what that I block a couple of threads – it will give me a benefit of writing completely synchronous code! So are there any other reasons why it’s unacceptable to do that? I am looking for some reasons beyond the common understanding, like is there such a thing that an operating system would hate my process for blocking threads? Or maybe, this is somehow deeply inefficient?