views:

150

answers:

2

Could someone provide a layman definition and use case?

+9  A: 

"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.)

T.J. Crowder
how does this differ from synchronous/asynchronous?
alfredo
@Jackie: Not *very* much, but there is a difference. Typically you'd see the term "blocking" around a call that will return data (or what have you) as part of that call (my socket read example; it waits [blocking] or doesn't [non-blocking], but you get the data -- or don't -- as an immediate effect of the call), whereas you'd hear "asynchronous" around a request-then-check-back (or receive callback) model. But they're closely related concepts. I guess you hear "blocking" around things that are *already* asynchronous in some way (network comms, my recurring example) more than not.
T.J. Crowder
It would seem like non-blocking is for asynchronous communication and blocking is synchronous communication, but that is not quite true.Synchronous code can use non-blocking calls (e.g. in a loop, though it is not quite practical) and asynchronous code often uses blocking calls (first obtains information if and which connection needs attention, then calls the 'blocking' function, already knowing it will not block).
Jacek Konieczny
+1  A: 

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.

friederbluemle
how does this differ from synchronous/asynchronous?
alfredo