On blocking and non-blocking system calls, which are preferable? Which ones are used the most? Thanks.
On blocking and non-blocking system calls, which are preferable? Which ones are used the most? Thanks.
It depends on what you want to do, programming styles, paradigms, etc.
The calls blocking, are those that (simplifying), wait and "block" (forgive the redundancy) the thread / process in which they are executed. All the examples that come to mind right now have to do with IO but surely there must be someone who does something else.
Generally you use "blocking" calls when the application will not execute several tasks at the same time or when the tasks need to wait (synchronize) for external events or data. Now, this is not so rigid either, you can have a system doing IO blocking on one thread and calculating the digits of PI
on the other and even though you are using read
(which locks the thread) the program does not "hang" on you .
Asynchronous calls, non-blocking or as you find them in literature use another philosophy. Basically your application keeps doing its things until the necessary resources for the call are available and then the kernel (again, I'm thinking about epoll
that is input and output) notifies that everything is ready and executes the call. In this paradigm the callbacks and the reactors (reactors) or loops of IO are very common.
In short, there is no "better" or "worse", there is "the right thing for each case" (and even "what less work takes the programmer").