VS异步非阻塞 [英] asynchronous vs non-blocking

查看:184
本文介绍了VS异步非阻塞的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是异步非阻塞调用之间的区别?此外阻塞和同步调用之间(举例请)?

What is the difference between asynchronous and non-blocking calls? Also between blocking and synchronous calls (with examples please)?

推荐答案

在许多情况下,它们是同一事物的不同的名称,但在某些情况下,他们有很大的不同。所以要看情况。术语是不是在整个软件行业是完全一致的方式使用。

In many circumstances they are different names for the same thing, but in some contexts they are quite different. So it depends. Terminology is not applied in a totally consistent way across the whole software industry.

例如在经典的套接字API,一个非阻塞套接字是一个简单,配有特殊立即返回会阻止的错误消息,而阻塞套接字会受阻。你必须使用一个单独的函数,如选择调查来找出何时是一个很好的时间重试。

For example in the classic sockets API, a non-blocking socket is one that simply returns immediately with a special "would block" error message, whereas a blocking socket would have blocked. You have to use a separate function such as select or poll to find out when is a good time to retry.

但异步套接字(通过Windows套接字所支持的),或.NET使用的异步IO模式,都比较方便。你调用一个方法来启动操作,当它完成了框架调用你回来。即使在这里,也有根本的不同。异步的Win32通过传递窗口消息插座元帅他们的结果到一个特定的GUI线程,而.NET异步IO是自由线程(你不知道什么线程你的回调将被调用)。

But asynchronous sockets (as supported by Windows sockets), or the asynchronous IO pattern used in .NET, are more convenient. You call a method to start an operation, and the framework calls you back when it's done. Even here, there are basic differences. Asynchronous Win32 sockets "marshal" their results onto a specific GUI thread by passing Window messages, whereas .NET asynchronous IO is free-threaded (you don't know what thread your callback will be called on).

所以,他们并不总是意味着同样的事情。要提炼插座的例子,我们可以说:

So they don't always mean the same thing. To distil the socket example, we could say:


  • 禁止和同步意味着同样的事情:你调用API,它挂上线程,直到它有某种形式的答案,并返回到您

  • 非阻塞意味着,如果答案不能迅速返回,该AP​​I一个错误立即返回,没有别的。因此必须有查询的API是否准备好被调用(即,以模拟一个等待以有效的方式,以避免在紧凑循环手册轮询)一些相关的方式。

  • 异步意味着API总是立即返回,已经开始了背景的努力满足您的要求,所以必须有一些相关的方法来获得结果。

这篇关于VS异步非阻塞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆