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.

  • 相关阅读:
    SQL-Duplicate Emails
    c#创建可比较对象
    c#扩展方法
    C#Lambda和委托
    C#集合
    c#显示实现接口和隐式实现的区别
    bs同时上传文件以及文件信息
    sql查询数据库中所有 ,数据为空的表
    sql查询所有表名和描述
    MES数据采集模块小结
  • 原文地址:https://www.cnblogs.com/codingforum/p/9083828.html
Copyright © 2011-2022 走看看