美文网首页
异步 同步 阻塞 非阻塞

异步 同步 阻塞 非阻塞

作者: laosijikaichele | 来源:发表于2018-02-26 15:25 被阅读9次

参考:
https://stackoverflow.com/questions/2625493/asynchronous-vs-non-blocking

它们之间的关系,不是固定的,取决于语境:

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.
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.
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:
Blocking and synchronous mean the same thing: you call the API, it hangs up the thread until it has some kind of answer and returns it to you.
Non-blocking means that if an answer can't be returned rapidly, the API returns immediately with an error and does nothing else. So there must be some related way to query whether the API is ready to be called (that is, to simulate a wait in an efficient way, to avoid manual polling in a tight loop).
Asynchronous means that the API always returns immediately, having started a "background" effort to fulfil your request, so there must be some related way to obtain the result.

相关文章

  • 谈论:同步异步阻塞非阻塞.md

    同步/异步:关注的方式(是否主动) 阻塞/非阻塞: 同步阻塞BIO: 同步非阻塞NIO: 异步非阻塞: 异步阻塞:

  • UNIX 的5种IO模型介绍

    IO模型同步、异步、阻塞、非阻塞socket阻塞与非阻塞,同步与异步 同步和异步 同步/异步主要针对C端-同步就像...

  • BIO NIO AIO

    BIO:同步阻塞IONIO:同步非阻塞IOAIO:异步非阻塞IO先弄清楚同步、异步,阻塞、非阻塞概念。 io操作分...

  • 阻塞非阻塞 同步异步 IO模型及其应用 NIO实现原理

    1.同步异步概念 2.阻塞非阻塞概念 3.常见I/O模型:同步阻塞IO,同步非阻塞IO,异步阻塞IO,异步非阻塞I...

  • IO模型

    原文参考链接 四种状态 同步 异步 阻塞 非阻塞 IO分类 同步阻塞IO 同步非阻塞IO 异步非阻塞IO注意: 没...

  • 阻塞,非阻塞,同步,异步

    阻塞,非阻塞,同步,异步

  • 同步、异步、阻塞、非阻塞,这下明白了

    同步阻塞,同步非阻塞,异步阻塞,异步非阻塞... 晕! 头! 转! 向! 对于小白来说,理解这些概念太难了。搜索这...

  • I/O模型

    一般来说I/O模型可以分为:同步阻塞,同步非阻塞,异步阻塞,异步非阻塞IO 同步阻塞IO:在此种方式下,用户进程在...

  • 并发、并行、同步、异步、阻塞、非阻塞

    并发 并行 同步 异步 阻塞 非阻塞

  • Java IO

    Before IO 分为:同步、异步阻塞、非阻塞 同步和异步是目的,阻塞和非阻塞是实现方式。 一个IO操作其实分成...

网友评论

      本文标题:异步 同步 阻塞 非阻塞

      本文链接:https://www.haomeiwen.com/subject/vqeyxftx.html