术语“阻塞”是什么意思?编程中的意思?
有人可以提供外行定义和用例吗?
Could someone provide a layman definition and use case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
有人可以提供外行定义和用例吗?
Could someone provide a layman definition and use case?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
“阻塞”意味着调用者等待,直到被调用者完成其处理。例如,来自套接字的“阻塞读取”会等待,直到有数据返回; “非阻塞”读取不会,它只是返回是否有读取的指示(通常是计数)。
您听到这个术语主要是围绕 API 来访问不一定需要 CPU 关注的资源(例如 I/O)。您还会在多线程中听到它:从线程 A 到线程 B 的调用可能被设计为“阻塞”(阻止线程 A),直到线程 B 达到处理或至少接受请求的相关状态。 (最明显的例子是“join”,它通常意味着“我,线程 A,想要等到线程 B 终止”——在退出多线程程序时使用它。)
"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.