Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the term "blocking" mean in programming?

Could someone provide a layman definition and use case?

like image 766
alfredo Avatar asked Mar 09 '10 08:03

alfredo


People also ask

What does blocking mean programming?

In computing, a process is an instance of a computer program that is being executed. A process always exists in exactly one process state. A process that is blocked is one that is waiting for some event, such as a resource becoming available or the completion of an I/O operation.

What does it mean when a function is blocking?

A function that stops script execution until it ends. For example, if I had a function in my language that was used to write to a file, like so: fwrite(file, "Contents"); print("Wrote to file!"); The print statement would only be executed once the file has been written to the disk.

What is a blocking process?

blocked process A process for which a process description exists but which is unable to proceed because it lacks some necessary resource. For example, a process may become blocked if it has inadequate memory available to it to allow the loading of the next part of the process. A Dictionary of Computing.

What is blocking call in C?

Blocking means that execution of your code (in that thread) will stop for the duration of the call. Essentially, the function call will not return until the blocking operation is complete. A blocking read will wait until there is data available (or a timeout, if any, expires), and then returns from the function call.


2 Answers

"Blocking" means that the caller waits until the callee finishes its processing. For instance, a "blocking read" from a socket waits until there is data to return; a "non-blocking" read does not, it just returns an indication (usually a count) of whether there was something read.

You hear the term mostly around APIs that access resources that don't necessarily require CPU attention -- I/O, for instance. You also hear it in multi-threading: A call from Thread A to Thread B might be designed to "block" (hold up Thread A) until Thread B achieves the relevant state to process or at least accept the request. (The most obvious example there being "join", which usually means "I, Thread A, want to wait until Thread B has terminated" -- you use that when exiting a multi-threaded program.)

like image 158
T.J. Crowder Avatar answered Oct 14 '22 14:10

T.J. Crowder


In simple words: If you call a function that stops the program from continuing to run until the user has performed some action (or some other action that your program is not controlling), this call is called a blocking call.

like image 45
friederbluemle Avatar answered Oct 14 '22 13:10

friederbluemle