术语“阻塞”是什么意思?编程中的意思?

发布于 2024-08-24 14:08:50 字数 22 浏览 5 评论 0原文

有人可以提供外行定义和用例吗?

Could someone provide a layman definition and use case?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只等公子 2024-08-31 14:08:50

“阻塞”意味着调用者等待,直到被调用者完成其处理。例如,来自套接字的“阻塞读取”会等待,直到有数据返回; “非阻塞”读取不会,它只是返回是否有读取的指示(通常是计数)。

您听到这个术语主要是围绕 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.)

偷得浮生 2024-08-31 14:08:50

简而言之:如果您调用一个函数来阻止程序继续运行,直到用户执行了某些操作(或您的程序无法控制的其他操作),则此调用称为阻塞调用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文