What's the difference between: Asynchronous, Non-Blocking, Event-Base architectures?

前端 未结 5 974
隐瞒了意图╮
隐瞒了意图╮ 2020-12-02 03:38
  1. What\'s the difference between:

    • Asynchronous,
    • Non-Blocking, and
    • Event-base archit
5条回答
  •  抹茶落季
    2020-12-02 04:12

    In an asynchronous hardware, code asks some entity to do something and is free to do other things while the action gets done; once the action is complete, the entity will typically signal the code in some fashion. A non-blocking architecture will make note of spontaneously-occurring actions which code might be interested in, and allow code to ask what such actions have occurred, but code will only come aware of such actions when it explicitly asks about them. An event-based architecture will affirmatively notify code when events spontaneously occur.

    Consider a serial port, from which code will want to receive 1,000 bytes.

    In a blocking-read architecture, the code will wait until either 1,000 bytes have arrived or it decides to give up.

    In an asynchronous-read architecture, the code will tell the driver it wants 1,000 bytes, and will be notified when 1,000 bytes have arrived.

    In a non-blocking architecture, the code may ask at any time how many bytes have arrived, and can read any or all such data when it sees fit, but the only way it can know when all the data has arrived is to ask; if the code wants to find out within a quarter second when the 1000th byte has arrived, it must check every quarter-second or so.

    In an event-based architecture, the serial port driver will notify the application any time any data arrives. The driver won't know how many bytes the application wants, so the application must be able to deal with notifications for amounts that are smaller or larger than what the application wants.

提交回复
热议问题