Context: Recently I was discussing the design of a small programme with a new team member (I am the product manager). The programme is essentially a protocol converter that reads data from a number of sockets (as a client) and inserts that data into the database. We discussed the idea of having one thread per socket to allow the programme to scale to more sockets without blocking itself. The same team member then discussed this (in general terms) with a senior dev who gave him the advice "threads should only ever block on one thing" i.e. if the same thread can block in two places, it should be two threads.
In the context of my programme, this would mean two threads per socket, or possibly one thread per socket plus one that does all the database insertions.
However, my question is not about my programme specifically but about the advice "threads should only ever block on one thing" - is this good advice to give to someone? Is it a well-known best practice? Or perhaps it derives from a particular school of thought or programming paradigm.
await
,async
methods return to their caller. That thread is free to do other work, i.e. the thread is not blocked. It makes better use of a thread, We can also mix async/await with multi threading.