zoukankan      html  css  js  c++  java
  • Parallel vs Synchronous vs Asynchronous

    [1] https://www.sohamkamani.com/blog/2016/03/14/wrapping-your-head-around-async-programming/

    [2] https://codewala.net/2015/07/29/concurrency-vs-multi-threading-vs-asynchronous-programming-explained/

    Parallel

    Parallelism means that two or more calculations happen simultaneously.

    Concurrency

    Concurrency means that two or more calculations happen within the same time frame, and there is usually some sort of dependency between them

    Synchronous Programming Model

    1. Single Threaded

    A thread is assigned to one task and starts working on it. Once the task completes then it is available for the next task. In this model, it cannot leave the executing task in mid to take up another task.

    So a thread could only execute task1 and then task2 and so on.

    2. Multi-threaded

    A typical thread pool/execurot service has a bunch of threads and each thread will pick up one task and finish it, before taking another task.

    Asynchronous Programming Model

    1. Single Threaded

    A thread once start executing a task, it can hold it in middle, save the current state and start executing another task.

    So a thread could execute task1, then task2 and then task1 again.

    2. Multi-threaded

    Multiple threads could be used to work on a bunch of tasks all together. so thread 1 could execute task1, save the state and then work on task2. In the meantime, thread 2 could work on task3, save the state and then work on task1, which was worked by thread 1.

    Every thread could work on one task, save the state and pickup the task that left by another thread.

    Synchronous vs Asynchronous 

    The whole point of asynchronous programming is to free up threads. This is especially important when we have many IO related tasks (network reading or writing, disk reading or writing). 

    For a web application, even if we just have one thread serving all incoming REST request, aysnchronous programming model will let the thread delegate the waiting time to other threads and return immediately to serve other requests. Non-stopping is the whole idea of asynchronous programming.

  • 相关阅读:
    Silverlight Control(五)TimePicker
    《ASP.NET Core 3框架揭秘》笔记
    Hyper-V初体验
    debian初体验
    异步编程-编程指南
    Oracle查询优化读书笔记
    设计原则
    日志管理
    Git在Vs中的使用
    SVN使用备注
  • 原文地址:https://www.cnblogs.com/codingforum/p/9083828.html
Copyright © 2011-2022 走看看