“阻塞"一词是什么意思?在编程中是什么意思? [英] What does the term "blocking" mean in programming?
问题描述
有人可以提供一个外行的定义和用例吗?
Could someone provide a layman 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.
您听到的这个术语主要是关于访问不一定需要 CPU 关注的资源的 API - 例如,I/O.您还可以在多线程中听到:从线程 A 到线程 B 的调用可能被设计为阻塞"(阻止线程 A),直到线程 B 达到相关状态来处理或至少接受请求.(最明显的例子是join",这通常意味着我,线程 A,想要等到线程 B 终止"——你在退出多线程程序时使用它.)
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.)
这篇关于“阻塞"一词是什么意思?在编程中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!