开发者

What does the term "blocking" mean in programming?

开发者 https://www.devze.com 2022-12-22 03:28 出处:网络
Could someone provide a laym开发者_如何学Can definition and use case?\"Blocking\" means that the caller waits until the callee finishes its processing. For instance, a \"blocking read\" from a socket

Could someone provide a laym开发者_如何学Can definition and use case?


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号